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 a service account. #130

Merged
merged 1 commit into from
Sep 26, 2024
Merged

Add a service account. #130

merged 1 commit into from
Sep 26, 2024

Conversation

plietar
Copy link
Member

@plietar plietar commented Sep 20, 2024

As part of adding support for authentication from OIDC tokens for GitHub actions, we need a user that we can assign to the tokens we issue. This adds a new user source, called "service", and populates the database with one of these accounts.

The service user is hidden from the API, and therefore is not visible in the control panel. Moreover, it cannot be given additional roles and permissions.

The service user has the ADMIN role, but in practice when issuing the access tokens we will restrict the actual scopes given to each token. As a precaution, I added some checks to make sure the different user sources cannot use users created by another.

@@ -0,0 +1,10 @@
WITH inserted_user AS (
Copy link
Member Author

Choose a reason for hiding this comment

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

I intentionally did not add a service role for the user. I don't think it is useful, and it opens the door to modifying that role through the API, which I'd rather avoid.

If we ever have a use case for it we can add it later as another migration.

@@ -62,12 +51,22 @@ class BaseRoleService(
return saveRole(createRole.name, permissions)
}

override fun createUsernameRole(username: String): Role
Copy link
Member Author

@plietar plietar Sep 20, 2024

Choose a reason for hiding this comment

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

This renames and changes the semantics of getUsernameRole a bit.

I found it confusing that a method called get has side-effects. I also don't think there's ever a valid use-case for returning an existing role, and it was opening up the door to someone creating a GitHub account whose username collides with an existing role, thereby gaining all of that roles permissions.

@plietar
Copy link
Member Author

plietar commented Sep 20, 2024

It's not really ready yet, but if you are curious you can look at #131 for how this gets used.

Copy link

codecov bot commented Sep 23, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 96.91%. Comparing base (1aa26e9) to head (7381cec).
Report is 23 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #130      +/-   ##
==========================================
+ Coverage   96.71%   96.91%   +0.19%     
==========================================
  Files         125      125              
  Lines        1156     1166      +10     
  Branches      317      319       +2     
==========================================
+ Hits         1118     1130      +12     
+ Misses         36       34       -2     
  Partials        2        2              
Flag Coverage Δ
96.91% <ø> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@plietar plietar force-pushed the service-user branch 4 times, most recently from 438a85b to 37f8836 Compare September 23, 2024 14:43
As part of adding support for authentication from OIDC tokens for GitHub
actions, we need a user that we can assign to the tokens we issue. This
adds a new user source, called "service", and populates the database
with one of these accounts.

The service user is hidden from the API, and therefore is not visible in
the control panel. Moreover, it cannot be given additional roles and
permissions.

The service user has the ADMIN role, but in practice when issuing the
access tokens we will restrict the actual scopes given to each token. As
a precaution, I added some checks to make sure the different user
sources cannot use users created by another.
Copy link
Contributor

@absternator absternator left a comment

Choose a reason for hiding this comment

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

Nice work!!! LGTM

@plietar plietar merged commit 223ba28 into main Sep 26, 2024
6 checks passed
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.

2 participants