Skip to content

Commit

Permalink
Closes #805 - Rename the configuration server's committer role (#829)
Browse files Browse the repository at this point in the history
  • Loading branch information
mariusoe committed Jul 10, 2020
1 parent 34bd6dc commit c3a5f2c
Show file tree
Hide file tree
Showing 15 changed files with 38 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const PromotionView = () => {
const currentApprovals = useSelector((state) => state.promotion.approvals);
const workspaceCommitId = useSelector((state) => state.promotion.workspaceCommitId);
const liveCommitId = useSelector((state) => state.promotion.liveCommitId);
const canCommit = useSelector((state) => state.authentication.permissions.commit);
const canPromote = useSelector((state) => state.authentication.permissions.promote);

// fetching promotion data
const [{ data, isLoading, lastUpdate }, refreshData] = useFetchData('/configuration/promotions', { 'include-content': 'true' });
Expand Down Expand Up @@ -140,7 +140,7 @@ const PromotionView = () => {
onRefresh={refreshData}
onPromote={() => setShowPromotionDialog(true)}
loading={isLoading}
enabled={canCommit && hasApprovals}
enabled={canPromote && hasApprovals}
/>
</div>
<div className="content">
Expand All @@ -157,7 +157,7 @@ const PromotionView = () => {
{currentSelectionFile ? (
<>
<PromotionFileViewer oldValue={currentSelectionFile.oldContent} newValue={currentSelectionFile.newContent} />
{canCommit && <PromotionFileApproval approved={isCurrentSelectionApproved} onApproveFile={toggleFileApproval} />}
{canPromote && <PromotionFileApproval approved={isCurrentSelectionApproved} onApproveFile={toggleFileApproval} />}
</>
) : (
<div className="selection-information">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const authentication = {
/** The authorization permissions the user has*/
permissions: {
write: false,
commit: false,
promote: false,
admin: false,
},
/** Specifying whether a login request is currently be executed */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ public class LdapRoleResolveSettings {
private List<String> write = new ArrayList<>();

/**
* Roles defined in this list are granted read, write and commit access.
* Roles defined in this list are granted read, write and promotion access.
*/
@Builder.Default
private List<String> commit = new ArrayList<>();
private List<String> promote = new ArrayList<>();

/**
* Roles defined in this list are granted read, write, commit and admin access.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ public class AgentMapping implements Auditable {
*/
private String name;

/**
* The branch which is used by this mapping.
*/
private Branch sourceBranch;

/**
Expand All @@ -46,7 +49,7 @@ public class AgentMapping implements Auditable {
@JsonCreator
public AgentMapping(
@JsonProperty("name") String name,
@JsonProperty("branch") Branch sourceBranch,
@JsonProperty("sourceBranch") Branch sourceBranch,
@JsonProperty("sources") List<@NotBlank String> sources,
@JsonProperty("attributes") Map<@NotBlank String, @NotBlank String> attributes) {
this.name = name;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public WorkspaceDiff getPromotions(@ApiParam("Specifies whether the old and new
return fileManager.getWorkspaceDiff(includeContent);
}

@Secured(UserRoleConfiguration.COMMIT_ACCESS_ROLE)
@Secured(UserRoleConfiguration.PROMOTE_ACCESS_ROLE)
@ApiOperation(value = "Promote configurations", notes = "Promotes the specified configuration files.")
@PostMapping(value = "configuration/promote")
public ResponseEntity promoteConfiguration(@ApiParam("The definition that contains the information about which files to promote.") @RequestBody ConfigurationPromotion promotion) throws GitAPIException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public UserPermissions getPermissions(Authentication auth) {

return UserPermissions.builder()
.write(roles.contains(UserRoleConfiguration.WRITE_ACCESS_ROLE))
.commit(roles.contains(UserRoleConfiguration.COMMIT_ACCESS_ROLE))
.promote(roles.contains(UserRoleConfiguration.PROMOTE_ACCESS_ROLE))
.admin(roles.contains(UserRoleConfiguration.ADMIN_ACCESS_ROLE))
.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public class UserRoleConfiguration {
/**
* Permission required for commit access.
*/
public static final String COMMIT_ACCESS_ROLE = ROLE_PREFIX + "OCELOT_COMMIT";
public static final String PROMOTE_ACCESS_ROLE = ROLE_PREFIX + "OCELOT_PROMOTE";

/**
* Permission required for admin access.
Expand All @@ -63,10 +63,10 @@ public class UserRoleConfiguration {
/**
* Permission set for the committer-role.
*/
public static final List<? extends GrantedAuthority> COMMIT_ROLE_PERMISSION_SET = Arrays.asList(
public static final List<? extends GrantedAuthority> PROMOTE_ROLE_PERMISSION_SET = Arrays.asList(
new SimpleGrantedAuthority(READ_ACCESS_ROLE),
new SimpleGrantedAuthority(WRITE_ACCESS_ROLE),
new SimpleGrantedAuthority(COMMIT_ACCESS_ROLE)
new SimpleGrantedAuthority(PROMOTE_ACCESS_ROLE)
);

/**
Expand All @@ -75,7 +75,7 @@ public class UserRoleConfiguration {
public static final List<? extends GrantedAuthority> ADMIN_ROLE_PERMISSION_SET = Arrays.asList(
new SimpleGrantedAuthority(READ_ACCESS_ROLE),
new SimpleGrantedAuthority(WRITE_ACCESS_ROLE),
new SimpleGrantedAuthority(COMMIT_ACCESS_ROLE),
new SimpleGrantedAuthority(PROMOTE_ACCESS_ROLE),
new SimpleGrantedAuthority(ADMIN_ACCESS_ROLE)
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ public Collection<? extends GrantedAuthority> mapAuthorities(Collection<? extend
if (containsAuthority(authorities, role_settings.getAdmin()) || hasAdminGroup(authorities)) {
return UserRoleConfiguration.ADMIN_ROLE_PERMISSION_SET;
}
if (containsAuthority(authorities, role_settings.getCommit())) {
return UserRoleConfiguration.COMMIT_ROLE_PERMISSION_SET;
if (containsAuthority(authorities, role_settings.getPromote())) {
return UserRoleConfiguration.PROMOTE_ROLE_PERMISSION_SET;
}
if (containsAuthority(authorities, role_settings.getWrite())) {
return UserRoleConfiguration.WRITE_ROLE_PERMISSION_SET;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ public class UserPermissions {
private boolean write;

/**
* True, if the user has commit access.
* True, if the user has promote access.
*/
private boolean commit;
private boolean promote;

/**
* True, if the user has admin access.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ inspectit-config-server:
# security settings
security:
# Whether LDAP authentication should be used
# See the documentation on how to configure LDAP correctly: https://inspectit.github.io/inspectit-ocelot/docs/config-server/user-authentication
ldap-authentication: false

# ACTUATOR PROPERTIES
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public void successfullyWriteYaml() throws IOException {
verify(fileAccessor).writeAgentMappings(writtenFile.capture());

assertThat(writtenFile.getValue()).isEqualTo("- name: \"mapping\"\n" +
" branch: \"LIVE\"\n" +
" sourceBranch: \"LIVE\"\n"+
" sources:\n" +
" - \"/any-source\"\n" +
" attributes:\n" +
Expand All @@ -64,9 +64,9 @@ public void successfullyWriteYaml() throws IOException {
public class ReadAgentMappings {

@Test
public void successfullyReadYaml() throws IOException {
public void successfullyReadYaml() {
String dummyYaml = "- name: \"mapping\"\n" +
" branch: \"WORKSPACE\"\n" +
" sourceBranch: \"LIVE\"\n" +
" sources:\n" +
" - \"/any-source\"\n" +
" attributes:\n" +
Expand All @@ -81,6 +81,7 @@ public void successfullyReadYaml() throws IOException {
assertThat(mapping.getName()).isEqualTo("mapping");
assertThat(mapping.getSources()).containsExactly("/any-source");
assertThat(mapping.getAttributes()).containsEntry("key", "val");
assertThat(mapping.getSourceBranch()).isEqualTo(Branch.LIVE);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ void testAdminPermissions() {
assertThat(result.getBody())
.isEqualTo(UserPermissions.builder()
.write(true)
.commit(true)
.promote(true)
.admin(true)
.build());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public InspectitServerSettings setupRoleSettings(

lenient().when(mockLdapRoleResolveSettings.getRead()).thenReturn(read);
lenient().when(mockLdapRoleResolveSettings.getWrite()).thenReturn(write);
lenient().when(mockLdapRoleResolveSettings.getCommit()).thenReturn(commit);
lenient().when(mockLdapRoleResolveSettings.getPromote()).thenReturn(commit);
lenient().when(mockLdapRoleResolveSettings.getAdmin()).thenReturn(admin);


Expand Down Expand Up @@ -100,18 +100,18 @@ public void hasWrite() {

@Test
public void hasCommit() {
List<SimpleGrantedAuthority> test_permission_set = Collections.singletonList(new SimpleGrantedAuthority("ROLE_commit"));
List<SimpleGrantedAuthority> test_permission_set = Collections.singletonList(new SimpleGrantedAuthority("ROLE_promote"));
customUserAuthoritiesMapper = new CustomUserAuthoritiesMapper(setupRoleSettings(
Collections.emptyList(),
Collections.emptyList(),
Collections.singletonList("commit"),
Collections.singletonList("promote"),
Collections.emptyList()
));

Collection<? extends GrantedAuthority> output = customUserAuthoritiesMapper.mapAuthorities(test_permission_set);

assertThat(output).hasSize(3);
assertThat(output).isEqualTo(UserRoleConfiguration.COMMIT_ROLE_PERMISSION_SET);
assertThat(output).isEqualTo(UserRoleConfiguration.PROMOTE_ROLE_PERMISSION_SET);
}

@Test
Expand All @@ -136,7 +136,7 @@ public void hasMultiple() {
customUserAuthoritiesMapper = new CustomUserAuthoritiesMapper(setupRoleSettings(
Collections.singletonList("read"),
Collections.singletonList("write"),
Collections.singletonList("commit"),
Collections.singletonList("promote"),
Collections.singletonList("admin")
));
Collection<? extends GrantedAuthority> output = customUserAuthoritiesMapper.mapAuthorities(test_permission_set);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public void successfullyFindUser() {
assertThat(result.getPassword()).isEqualTo("hash");
assertThat(result.getAuthorities())
.extracting(object -> object.toString().substring("ROLE_".length()))
.containsExactlyInAnyOrder("OCELOT_WRITE", "OCELOT_READ", "OCELOT_COMMIT", "OCELOT_ADMIN");
.containsExactlyInAnyOrder("OCELOT_WRITE", "OCELOT_READ", "OCELOT_PROMOTE", "OCELOT_ADMIN");
verify(userService).getUserByName(anyString());
verifyNoMoreInteractions(userService);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@ The LDAP related configuration properties have to be specified using the propert

### Authorization

There are four different access roles available: read, write, commit and admin. These access roles are hierarchical.
A user with write access also has read access, a user with commit access also has both read and write access and so on.
There are four different access roles available: read, write, promote and admin. These access roles are hierarchical.
A user with write access also has read access, a user with promote access also has both read and write access and so on.
The exact permissions of the roles are the following:

* *Read*: may only read files on the server.
* *Write*: may read and edit files on the server.
* *Commit*: may read, write and commit files (This feature is not implemented yet).
* *Admin*: may read, write and commit files. Can also edit user accounts.
* *Promote*: may read, write and promote files.
* *Admin*: may read, write and promote files. Can also edit user accounts.

#### Configuration

Expand All @@ -59,7 +59,7 @@ Each property is located below the property `inspectit-config-server.security.ld
| `group-search-filter` | The LDAP filter to search for groups. |
| `roles.read` | A list of LDAP-Groups which will gain read-access. |
| `roles.write` | A list of LDAP-Groups which will gain write-access. |
| `roles.commit` | A list of LDAP-Groups which will gain commit-access. |
| `roles.promote` | A list of LDAP-Groups which will gain promote-access. |
| `roles.admin` | A list of LDAP-Groups which will gain admin-access. |

The following configuration snippet shows an example LDAP configuration (this configuration was created for [this](https://github.com/rroemhild/docker-test-openldap) LDAP server).
Expand All @@ -80,7 +80,7 @@ inspectit-config-server:
roles:
read: []
write: []
commit: []
promote: []
admin:
- SHIP_CREW
```
Expand Down

0 comments on commit c3a5f2c

Please sign in to comment.