-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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.
- Loading branch information
Showing
14 changed files
with
221 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
api/app/src/main/resources/db/migration/V20240919__create_service_account.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
WITH inserted_user AS ( | ||
INSERT INTO "user"("username", "display_name", "user_source") | ||
VALUES ('service', 'Service Account', 'service') | ||
RETURNING id | ||
) | ||
INSERT INTO "user_role"("user_id", "role_id") | ||
SELECT inserted_user.id, role.id | ||
FROM inserted_user | ||
CROSS JOIN "role" | ||
WHERE role.name = 'ADMIN'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
package packit.integration.controllers | ||
|
||
import com.fasterxml.jackson.core.type.TypeReference | ||
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper | ||
import org.springframework.beans.factory.annotation.Autowired | ||
import org.springframework.core.ParameterizedTypeReference | ||
import org.springframework.http.HttpMethod | ||
import org.springframework.http.HttpStatus | ||
import org.springframework.test.context.TestPropertySource | ||
|
@@ -158,6 +158,28 @@ class UserControllerTest : IntegrationTest() | |
assertEquals(userRepository.findByUsername(testUser.username), null) | ||
assertEquals(roleRepository.findByName(username), null) | ||
} | ||
|
||
@Test | ||
@WithAuthenticatedUser(authorities = ["user.manage"]) | ||
fun `getAllUsers excludes service accounts`() | ||
{ | ||
userRepository.save( | ||
User(username = "[email protected]", userSource = "service") | ||
) | ||
userRepository.save( | ||
User(username = "[email protected]", userSource = "basic") | ||
) | ||
|
||
val result = restTemplate.exchange( | ||
"/user", | ||
HttpMethod.GET, | ||
getTokenizedHttpEntity(), | ||
object : ParameterizedTypeReference<List<UserDto>>() {} | ||
) | ||
|
||
val body = assertSuccess(result) | ||
assertEquals(body.map { it.username }, listOf("[email protected]")) | ||
} | ||
} | ||
|
||
@Sql("/delete-test-users.sql", executionPhase = Sql.ExecutionPhase.AFTER_TEST_METHOD) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.