Skip to content
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

Closed
wants to merge 1 commit into from

Conversation

harsh-ps-2003
Copy link
Contributor

@harsh-ps-2003 harsh-ps-2003 commented Aug 10, 2023

Signed-off-by: Harsh Pratap Singh [email protected]
Fixes #5390

  • I added CHANGELOG entry for this change.
  • Change is not relevant to the end user.

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:
Screenshot 2023-08-10 at 11 52 37 AM
Screenshot 2023-08-10 at 12 04 49 PM
The API test:

❯ curl -X POST -d "id=_ulid&action=DELETION" http://localhost:8080/api/v1/blocks/mark

{"status":"error","errorType":"bad_data","error":"Admin operations are disabled"}

cc @yeya24 @GiedriusS @saswatamcode

Signed-off-by: Harsh Pratap Singh <[email protected]>
Copy link
Member

@saswatamcode saswatamcode left a 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",
Copy link
Member

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?

Copy link
Contributor Author

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.

Copy link
Member

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)

Copy link
Contributor Author

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))
Copy link
Member

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

Copy link
Contributor Author

@harsh-ps-2003 harsh-ps-2003 Aug 10, 2023

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.

Copy link
Member

@saswatamcode saswatamcode Aug 10, 2023

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

Copy link
Contributor Author

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)
Copy link
Member

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

Copy link
Contributor Author

@harsh-ps-2003 harsh-ps-2003 Aug 10, 2023

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

Copy link
Member

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.

Copy link
Contributor Author

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

Comment on lines +44 to +54
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();
}, []);

Copy link
Member

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

Copy link
Contributor Author

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;

@harsh-ps-2003 harsh-ps-2003 deleted the addingflag branch August 10, 2023 15:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Provide option to disable block mark deletion and mark no compaction from bucket UI
2 participants