Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@pjain1
Copy link
Member

@pjain1 pjain1 commented Jun 18, 2025

Fixes https://linear.app/rilldata/issue/PLAT-50/support-roles-and-attributes-for-services

// ways to create a service with optional org, project role and attributes
rill service create test-svc  --org test --org-role viewer 
rill service create test-svc  --org test --org-role viewer --project test --project-role admin 
rill service create test-svc  --org test --org-role viewer --project test --project-role admin --attributes '{"k": "v"}'

// to set attributes on service, this overrides the previous as of now
rill service edit test-svc --attributes '{"k": "v1"}' 

// to set org role on a service
rill service set-role  
rill service set-role --project test // to add or change project role on service

// remove org level role for service
rill service remove test-svc 
// remove project level role for service
rill service remove test-svc --project test 

// list org level services
rill service list 
rill service list --project test // list project level services

// show service details including projects its part of
rill service show test-svc

Checklist:

  • Covered by tests
  • Ran it and it works as intended
  • Reviewed the diff before requesting a review
  • Checked for unhandled edge cases
  • Linked the issues it closes
  • Checked if the docs need to be updated. If so, create a separate Linear DOCS issue
  • Intend to cherry-pick into the release branch
  • I'm proud of this work!

@pjain1 pjain1 marked this pull request as draft June 18, 2025 20:15
@pjain1 pjain1 requested a review from begelundmuller June 20, 2025 05:11
@pjain1 pjain1 marked this pull request as ready for review June 20, 2025 05:11
@pjain1 pjain1 changed the title support roles and attrs on services PLAT-50: support roles and attrs on services Jun 20, 2025
@pjain1 pjain1 requested a review from begelundmuller June 27, 2025 12:39
Comment on lines 192 to 204
// If no roles are found, check if the service belongs to the org of the project
service, err := s.DB.FindService(ctx, serviceID)
if err != nil {
return nil, err
}

proj, err := s.DB.FindProject(ctx, projectID)
if err != nil {
return nil, err
}

// Services get read permissions on the projects of the org they belong to
if proj.OrganizationID == service.OrgID {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this needs to be removed now? Otherwise if it has no project roles, it would get access to all projects?

For backwards compatibility for the services with the admin org role, I believe the if orgPerms.ManageProjects case above covers them.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Otherwise if it has no project roles, it would get access to all projects?

Yes this is intended behaviour, if a service is added as a viewer or any other role than admin to org then it should have read permission on project. Otherwise whats the use of org level roles?

Copy link
Member Author

@pjain1 pjain1 Jul 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Although this should change to check if any org role exists for service if not then return empty permissions

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

made the change

Comment on lines 39 to 41
if orgRole == "" && projectRole == "" {
return fmt.Errorf("either --org-role or --project-role must be specified")
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not ideal to require a flag (since flags are usually optional). What do you think would be a nice behavior here?

Copy link
Member Author

@pjain1 pjain1 Jul 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should I just include a prompt saying if no orgRole or projectRole is provide then service will be created with admin role on org level otherwise use either --org-role or --project-role to set a role? Use can accept or deny the prompt.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another option is to to prompt for whether they want to add an org role or not and give role options to select from, similar for project name and roles. That will solve this as well.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed the flow please check

string org_role_name = 3; // Optional org role to assign
string project_name = 4; // Optional project to assign role to
string project_role_name = 5; // Optional project role to assign
map<string, string> attributes = 6;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would about non-string types, like admin (bool) or groups (array)? Consider using either google.protobuf.Struct passing it as JSON, e.g. string attributes_json.

If you use google.protobuf.Struct, I think you can add optional in front – maybe that solves the issue about ability to clear attributes?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed to use google.protobuf.Struct

@pjain1 pjain1 requested a review from begelundmuller July 3, 2025 16:31
@pjain1 pjain1 merged commit 76fe98f into main Jul 4, 2025
14 checks passed
@pjain1 pjain1 deleted the service_roles branch July 4, 2025 15:07
grahamplata pushed a commit that referenced this pull request Jul 8, 2025
* support roles and attrs on services

* proto lint

* fixes

* manual fixes

* gen fixes

* fixes

* fix persistent flag

* runtime proxy fix

* review comments

* refactor

* review comments

* add service name as args to remove cmd

* fix e2e

* add --interactive=false

* review comments

* remove interactive flag from ui test
grahamplata pushed a commit that referenced this pull request Jul 8, 2025
* support roles and attrs on services

* proto lint

* fixes

* manual fixes

* gen fixes

* fixes

* fix persistent flag

* runtime proxy fix

* review comments

* refactor

* review comments

* add service name as args to remove cmd

* fix e2e

* add --interactive=false

* review comments

* remove interactive flag from ui test
royendo added a commit that referenced this pull request Nov 3, 2025
- Create new service-tokens.md page in /manage section covering:
  - Overview and use cases for service tokens
  - Creating tokens with roles and custom attributes
  - Organization and project-level role management
  - Custom attributes for fine-grained access control
  - Managing and editing service tokens
  - Using attributes with security policies
  - Issuing ephemeral tokens
  - Best practices and troubleshooting

- Update /integrate/custom-api.md:
  - Document custom attributes for service tokens
  - Add examples of using attributes with security policies
  - Link to comprehensive service tokens documentation
  - Remove outdated information about admin-only access

- Update /integrate/embedding.md:
  - Improve service token creation examples with roles
  - Update references to new service tokens documentation

- Update /build/metrics-view/security.md:
  - Add service token custom attributes example
  - Link to service tokens documentation

- Update /manage/index.md:
  - Add service tokens to Access Control section

Related to PR #7480 which added custom attributes support

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants