Skip to content

Commit 361fbd9

Browse files
authored
Merge pull request #294 from kbss-cvut/keycloak-migration-doc
Keycloak migration
2 parents 6210220 + a695797 commit 361fbd9

File tree

12 files changed

+166
-66
lines changed

12 files changed

+166
-66
lines changed

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,8 @@ junit.xml
88
.DS_store
99

1010
.env
11+
12+
# terraform
13+
.terraform/
14+
terraform.tfstate
15+
terraform.tfstate.backup

config/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,5 @@ export const BASENAME = getEnv("BASENAME", "");
3434
export const EXTENSIONS = getEnv("EXTENSIONS", "");
3535
export const APP_INFO = getEnv("APP_INFO", "© KBSS at FEE CTU in Prague, 2024");
3636
export const ANALYTICS_URL = getEnv("ANALYTICS_URL", "");
37+
38+
export const AUTHENTICATION = getEnv("AUTHENTICATION", "");
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
services:
2+
keycloak-config:
3+
image: hashicorp/terraform:light
4+
working_dir: /workspace
5+
volumes:
6+
- ./keycloak-config:/workspace
7+
depends_on:
8+
- auth-server
9+
entrypoint: ["/bin/sh", "-c"]
10+
environment:
11+
- TF_VAR_kc_admin_user=${KC_ADMIN_USER}
12+
- TF_VAR_kc_admin_password=${KC_ADMIN_PASSWORD}
13+
- TF_VAR_kc_realm=record-manager
14+
- TF_VAR_kc_url=http://auth-server:8080/
15+
command: >
16+
"until nc -z auth-server 8080; do sleep 1; done &&
17+
terraform init &&
18+
terraform apply -auto-approve"

deploy/keycloak-auth/docker-compose.yml

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -142,24 +142,6 @@ services:
142142
depends_on:
143143
- auth-server-db
144144

145-
keycloak-config:
146-
image: hashicorp/terraform:light
147-
working_dir: /workspace
148-
volumes:
149-
- ./keycloak-config:/workspace
150-
depends_on:
151-
- auth-server
152-
entrypoint: ["/bin/sh", "-c"]
153-
environment:
154-
- TF_VAR_kc_admin_user=${KC_ADMIN_USER}
155-
- TF_VAR_kc_admin_password=${KC_ADMIN_PASSWORD}
156-
- TF_VAR_kc_realm=record-manager
157-
- TF_VAR_kc_url=http://auth-server:8080/
158-
command: >
159-
"until nc -z auth-server 8080; do sleep 1; done &&
160-
terraform init &&
161-
terraform apply -auto-approve"
162-
163145
volumes:
164146
db-server:
165147
auth-server:

deploy/keycloak-auth/keycloak-config/.terraform.lock.hcl

Lines changed: 27 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

deploy/keycloak-auth/keycloak-config/groups_and_mapping.tf

Lines changed: 0 additions & 22 deletions
This file was deleted.
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
# Define the role groups and their associated roles
2+
variable "role_groups" {
3+
type = map(list(string))
4+
default = {
5+
admin-role-group = [
6+
"read-all-records-role",
7+
"write-all-records-role",
8+
"read-organization-records-role",
9+
"write-organization-records-role",
10+
"complete-records-role",
11+
"reject-records-role",
12+
"publish-records-role",
13+
"import-codelists-role",
14+
"comment-record-questions-role",
15+
"read-all-users-role",
16+
"write-all-users-role",
17+
"read-organization-users-role",
18+
"write-organization-users-role",
19+
"read-organization-role",
20+
"write-organization-role",
21+
"read-all-organizations-role",
22+
"write-all-organizations-role",
23+
"read-action-history-role",
24+
"read-statistics-role"
25+
]
26+
data-collection-coordinator-role-group = [
27+
"read-all-users-role",
28+
"write-all-users-role",
29+
"read-organization-users-role",
30+
"write-organization-users-role",
31+
"read-organization-role",
32+
"write-organization-role",
33+
"read-all-organizations-role",
34+
"write-all-organizations-role",
35+
"read-organization-records-role",
36+
"write-organization-records-role",
37+
"comment-record-questions-role",
38+
"complete-records-role"
39+
]
40+
organization-manager-role-group = [
41+
"read-organization-role",
42+
"write-organization-role",
43+
"read-organization-users-role",
44+
"write-organization-users-role",
45+
"read-organization-records-role",
46+
"write-organization-records-role",
47+
"comment-record-questions-role"
48+
]
49+
entry-clerk-role-group = [
50+
"read-organization-role",
51+
"read-organization-records-role",
52+
"comment-record-questions-role"
53+
]
54+
reviewer-role-group = [
55+
"complete-records-role",
56+
"comment-record-questions-role"
57+
]
58+
}
59+
}
60+
61+
# Create the groups
62+
resource "keycloak_group" "role_groups" {
63+
for_each = var.role_groups
64+
65+
realm_id = var.kc_realm
66+
name = each.key
67+
}
68+
69+
# Assign ALL roles to each group in a single resource
70+
resource "keycloak_group_roles" "group_role_assignments" {
71+
for_each = var.role_groups
72+
73+
realm_id = var.kc_realm
74+
group_id = keycloak_group.role_groups[each.key].id
75+
76+
role_ids = [
77+
for role_name in each.value :
78+
keycloak_role.realm_roles[role_name].id
79+
]
80+
}
Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,25 @@
11
variable "roles" {
22
type = map(string)
33
default = {
4-
rm-delete-all-records = ""
5-
rm-edit-users = ""
6-
rm-impersonate = ""
7-
rm-edit-all-records = ""
8-
rm-view-organization-records = ""
9-
rm-complete-records = ""
10-
rm-edit-organization-records = ""
11-
rm-view-all-records = ""
12-
rm-delete-organization-records = ""
13-
rm-publish-records = ""
14-
rm-import-codelists = ""
15-
rm-reject-records = ""
4+
read-all-records-role = "",
5+
write-all-records-role = "",
6+
read-organization-records-role = "",
7+
write-organization-records-role = "",
8+
complete-records-role = "",
9+
reject-records-role = "",
10+
publish-records-role = "",
11+
import-codelists-role = "",
12+
comment-record-questions-role = "",
13+
read-all-users-role = "",
14+
write-all-users-role = "",
15+
read-organization-users-role = "",
16+
write-organization-users-role = "",
17+
read-organization-role = "",
18+
write-organization-role = "",
19+
read-all-organizations-role = "",
20+
write-all-organizations-role = "",
21+
read-action-history-role = "",
22+
read-statistics-role = ""
1623
}
1724
}
1825

@@ -22,4 +29,4 @@ resource "keycloak_role" "realm_roles" {
2229
realm_id = var.kc_realm
2330
name = each.key
2431
description = length(each.value) > 0 ? each.value : null
25-
}
32+
}

src/components/institution/InstitutionSelector.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import PropTypes from "prop-types";
88
const InstitutionSelector = ({ currentUser, user, onInstitutionSelected, generateInstitutionsOptions }) => {
99
const { i18n } = useI18n();
1010

11-
return canSelectInstitution(currentUser) ? (
11+
return canSelectInstitution(currentUser, user) ? (
1212
<HorizontalInput
1313
type="select"
1414
name="institution"

src/components/user/User.jsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ class User extends React.Component {
238238
type="text"
239239
name="firstName"
240240
label={`${this.i18n("user.first-name")}*`}
241-
disabled={!canWriteUserInfo(currentUser, user)}
241+
disabled={isUsingOidcAuth() || !canWriteUserInfo(currentUser, user)}
242242
value={user.firstName}
243243
labelWidth={3}
244244
inputWidth={8}
@@ -250,7 +250,7 @@ class User extends React.Component {
250250
type="text"
251251
name="lastName"
252252
label={`${this.i18n("user.last-name")}*`}
253-
disabled={!canWriteUserInfo(currentUser, user)}
253+
disabled={isUsingOidcAuth() || !canWriteUserInfo(currentUser, user)}
254254
value={user.lastName}
255255
labelWidth={3}
256256
inputWidth={8}
@@ -277,7 +277,7 @@ class User extends React.Component {
277277
type="email"
278278
name="emailAddress"
279279
label={`${this.i18n("users.email")}*`}
280-
disabled={!canWriteUserInfo(currentUser, user)}
280+
disabled={isUsingOidcAuth() || !canWriteUserInfo(currentUser, user)}
281281
value={user.emailAddress}
282282
labelWidth={3}
283283
inputWidth={8}

0 commit comments

Comments
 (0)