-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add --disable-admin-operations
flag in Block Bucket UI
#6601
Conversation
Signed-off-by: Harsh Pratap Singh <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! Some comments,
bkt: bkt, | ||
disableCORS: disableCORS, | ||
bkt: bkt, | ||
disableAdminOperations: flagsMap["disable-admin-operations"] == "true", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's just pass the bool directly in NewBlockAPI, instead of using this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
actaully flagsMap map[string]string
will give a string "true" with flagsMap["disable-admin-operations"]
. thus I am simply converting it to boolean.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be cleaner and more consistent with other such options like disableCors, and we wouldn't need to check a string here at all
But actually, I think we don't even need any changes in BlocksAPI here. The flag value will just directly be used in UI anyway, so we don't need a separate API. See my other comment #6601 (comment)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
okay! thanks for the review. i will look into it!
@@ -84,9 +86,18 @@ func (bapi *BlocksAPI) Register(r *route.Router, tracer opentracing.Tracer, logg | |||
|
|||
r.Get("/blocks", instr("blocks", bapi.blocks)) | |||
r.Post("/blocks/mark", instr("blocks_mark", bapi.markBlock)) | |||
r.Get("/flags", instr("flags_disableAdminOperations", bapi.disableAdminOperationsHandler)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think you need to add a new API for this. We already register api/v1/status/flags
as a common endpoint for all components in pkg/api
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be cleaner and more consistent with other such options like disableCors, and we wouldn't need to check a string here at all
But actually, I think we don't even need any changes in BlocksAPI here. The flag value will just directly be used in UI anyway, so we don't need a separate API. See my other comment #6601 (comment)
@saswatamcode @GiedriusS @yeya24 one problem that I am facing when using /status/flags
endpoint is that I am not able to figure out how to get the flags value inside the markBlock
function of v1.go
. I need it so as to restrict access to the API when the flag is enabled.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ack! Reading the issue seems like we would need the option passed here as well. To restrict access, both via UI and API. Ignore this comment then,
But actually, I think we don't even need any changes in BlocksAPI here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks for the clarification!
@@ -203,6 +204,8 @@ func (tbc *bucketWebConfig) registerBucketWebFlag(cmd extkingpin.FlagClause) *bu | |||
cmd.Flag("timeout", "Timeout to download metadata from remote storage").Default("5m").DurationVar(&tbc.timeout) | |||
|
|||
cmd.Flag("label", "External block label to use as group title").StringVar(&tbc.label) | |||
|
|||
cmd.Flag("disable-admin-operations", "Restrict access to Block Mark deletion and no compaction").Default("false").BoolVar(&tbc.disableAdminOperations) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this flag be in Compactor (cmd/thanos/compact.go
) instead? As that is the component that exposes blocks UI
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I lack on a broader knowledge of codebase, but as far as I can understand, If i add the flag in compact.go then the flag will be available in Compactor UI instead of Bucket UI. I can tell this for sure that adding the flag in tools_bucket.go is only affecting Bucket UI. I think we want this flag specifically in Bucket UI not in the Compactor UI right? @yeya24 @GiedriusS @saswatamcode
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ack got confused for a bit. So Thanos users can access the Block UI via two ways I think,
tools bucket web
(i.e which is covered by the flag you added)compact
(which isn't covered)
So let's add the same flag there too, as you can mark deletion and no compaction there too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
okay! i will add the same flag for Compactor as well as Bucket
const fetchDisableAdminOperations = async () => { | ||
const response = await fetch('/api/v1/flags'); | ||
const result = await response.json(); | ||
setDisableAdminOperations(result.data.disableAdminOperations); | ||
console.log('disableAdminOperations', result.data.disableAdminOperations); | ||
}; | ||
|
||
useEffect(() => { | ||
fetchDisableAdminOperations(); | ||
}, []); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's try to do this from /status/flags endpoint directly. Take a look at how we use it for defaultStep
in PanelList : https://github.com/thanos-io/thanos/blob/main/pkg/ui/react-app/src/pages/graph/PanelList.tsx#L161
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
its actually very convinent. i use this in blockDetails.tsx and it worked like a charm :
const { response: flagsRes } = useFetch<FlagMap>(`/api/v1/status/flags`);
const disableAdminOperations = flagsRes?.data?.['disable-admin-operations'] || false;
Signed-off-by: Harsh Pratap Singh [email protected]
Fixes #5390
Changes
This PR adds a flag, named
--disable-admin-operations
, to Bucket Web UI to decide whether to disable the corresponding buttons Mark Deletion and Mark No Compaction in the UI as they are admin-level operations. It also restricts the API usage.Verification
It was tested locally.
The UI test:
The API test:
cc @yeya24 @GiedriusS @saswatamcode