Skip to content

Commit

Permalink
Merge pull request #3031 from uselagoon/openshift-view-permissions
Browse files Browse the repository at this point in the history
  • Loading branch information
tobybellwood authored Feb 23, 2022
2 parents 6ab1213 + fc25f1f commit a4f8a99
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 5 deletions.
2 changes: 1 addition & 1 deletion docs/administering-lagoon/rbac.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ Here is a table that lists the roles and the access they have:
| deleteOpenshift | openshift | delete | | Yes | Yes | No | No | No | No | No | |
| deleteAllOpenshifts | openshift | deleteAll | | Yes | Yes | No | No | No | No | No | |
| getAllOpenshifts | openshift | viewAll | | Yes | No | No | No | No | No | No | |
| getOpenshiftByProjectId | openshift | view | projectID | Yes | Yes | Yes | Yes | No | No | No | |
| getOpenshiftByProjectId | openshift | view | projectID | Yes | Yes | Yes | Yes | Yes | Yes | Yes | |
| addNotificationToProject | project | addNotification | projectID | Yes | Yes | Yes | Yes | No | No | No | |
| removeNotificationFromProject | project | removeNotification | projectID | Yes | Yes | Yes | Yes | No | No | No | |
| addProject | project | add | | Yes | Yes | Yes | Yes | Yes | Yes | Yes | |
Expand Down
7 changes: 4 additions & 3 deletions services/api/src/resources/openshift/resolvers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const attrFilter = async (hasPermission, entity) => {
await hasPermission('openshift', 'view:token');
return entity;
} catch (err) {
return R.omit(['token'], entity);
return R.omit(['token','consoleUrl','monitoringConfig'], entity);
}
};

Expand Down Expand Up @@ -126,12 +126,13 @@ export const getOpenshiftByEnvironmentId: ResolverFn = async (
{ sqlClientPool, hasPermission }
) => {
// get the project id for the environment
const { id: projectId } = await projectHelpers(
const project = await projectHelpers(
sqlClientPool
).getProjectByEnvironmentId(eid);

// check permissions on the project
await hasPermission('openshift', 'view', {
project: projectId
project: project.project
});

const rows = await query(
Expand Down
21 changes: 20 additions & 1 deletion services/keycloak/start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -765,7 +765,7 @@ EOF
"decisionStrategy": "UNANIMOUS",
"resources": ["openshift"],
"scopes": ["view"],
"policies": ["User has access to project","Users role for project is Maintainer"]
"policies": ["User has access to project","Users role for project is Guest"]
}
EOF

Expand Down Expand Up @@ -1673,6 +1673,24 @@ function remove_billing_modifier {
/opt/jboss/keycloak/bin/kcadm.sh delete -r lagoon clients/$CLIENT_ID/authz/resource-server/resource/$billing_modifier_resource_id --config $CONFIG_PATH
}

function update_openshift_view_permission {
CLIENT_ID=$(/opt/jboss/keycloak/bin/kcadm.sh get -r lagoon clients?clientId=api --config $CONFIG_PATH | python -c 'import sys, json; print json.load(sys.stdin)[0]["id"]')
echo Reconfiguring View Openshift
VIEW_OPENSHIFT_PERMISSION_ID=$(/opt/jboss/keycloak/bin/kcadm.sh get -r lagoon clients/$CLIENT_ID/authz/resource-server/permission?name=View+Openshift --config $CONFIG_PATH | python -c 'import sys, json; print json.load(sys.stdin)[0]["id"]')
/opt/jboss/keycloak/bin/kcadm.sh delete -r lagoon clients/$CLIENT_ID/authz/resource-server/permission/$VIEW_OPENSHIFT_PERMISSION_ID --config $CONFIG_PATH
/opt/jboss/keycloak/bin/kcadm.sh create clients/$CLIENT_ID/authz/resource-server/permission/scope --config $CONFIG_PATH -r lagoon -f - <<EOF
{
"name": "View Openshift",
"type": "scope",
"logic": "POSITIVE",
"decisionStrategy": "UNANIMOUS",
"resources": ["openshift"],
"scopes": ["view"],
"policies": ["User has access to project","Users role for project is Guest"]
}
EOF
}

function configure_keycloak {
until is_keycloak_running; do
echo Keycloak still not running, waiting 5 seconds
Expand All @@ -1698,6 +1716,7 @@ function configure_keycloak {
configure_harbor_scan_system
configure_advanced_task_system
remove_billing_modifier
update_openshift_view_permission

echo "Config of Keycloak done. Log in via admin user '$KEYCLOAK_ADMIN_USER' and password '$KEYCLOAK_ADMIN_PASSWORD'"

Expand Down

0 comments on commit a4f8a99

Please sign in to comment.