-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: enable keycloak with pre-configured agent in helm chart (#791)
Signed-off-by: Pat Losoponkul <[email protected]> Signed-off-by: Kranium Gikos Mendoza <[email protected]> Co-authored-by: Kranium Gikos Mendoza <[email protected]>
- Loading branch information
Showing
8 changed files
with
266 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
apiVersion: v1 | ||
kind: ConfigMap | ||
metadata: | ||
name: keycloak-bootstrap-script | ||
data: | ||
init.sh: | | ||
#!/usr/bin/env bash | ||
set -e | ||
set -u | ||
KEYCLOAK_BASE_URL=$KEYCLOAK_BASE_URL | ||
KEYCLOAK_ADMIN_USER=$KEYCLOAK_ADMIN_USER | ||
KEYCLOAK_ADMIN_PASSWORD=$KEYCLOAK_ADMIN_PASSWORD | ||
REALM_NAME=$REALM_NAME | ||
PRISM_AGENT_CLIENT_ID=$PRISM_AGENT_CLIENT_ID | ||
PRISM_AGENT_CLIENT_SECRET=$PRISM_AGENT_CLIENT_SECRET | ||
function get_admin_token() { | ||
local response=$( | ||
curl --request POST "$KEYCLOAK_BASE_URL/realms/master/protocol/openid-connect/token" \ | ||
--fail -s -v \ | ||
--data-urlencode "grant_type=password" \ | ||
--data-urlencode "client_id=admin-cli" \ | ||
--data-urlencode "username=$KEYCLOAK_ADMIN_USER" \ | ||
--data-urlencode "password=$KEYCLOAK_ADMIN_PASSWORD" | ||
) | ||
local access_token=$(echo $response | jq -r '.access_token') | ||
echo $access_token | ||
} | ||
function is_client_exists() { | ||
local access_token=$1 | ||
local client_id=$2 | ||
local http_status=$( | ||
curl --request GET "$KEYCLOAK_BASE_URL/admin/realms/$REALM_NAME/clients/$client_id" \ | ||
-s -w "%{http_code}" \ | ||
-o /dev/null \ | ||
-H "Authorization: Bearer $access_token" | ||
) | ||
if [ $http_status == 200 ]; then | ||
echo "true" | ||
else | ||
echo "false" | ||
fi | ||
} | ||
function create_client() { | ||
local access_token=$1 | ||
local client_id=$2 | ||
local client_secret=$3 | ||
curl --request POST "$KEYCLOAK_BASE_URL/admin/realms/$REALM_NAME/clients" \ | ||
--fail -s \ | ||
-H "Authorization: Bearer $access_token" \ | ||
-H "Content-Type: application/json" \ | ||
--data-raw "{ | ||
\"id\": \"$client_id\", | ||
\"directAccessGrantsEnabled\": true, | ||
\"authorizationServicesEnabled\": true, | ||
\"serviceAccountsEnabled\": true, | ||
\"secret\": \"$client_secret\" | ||
}" | ||
} | ||
echo "Getting admin access token ..." | ||
ADMIN_ACCESS_TOKEN=$(get_admin_token) | ||
CLIENT_EXIST=$(is_client_exists $ADMIN_ACCESS_TOKEN $PRISM_AGENT_CLIENT_ID) | ||
if [ $CLIENT_EXIST == "false" ]; then | ||
echo "Creating a new $PRISM_AGENT_CLIENT_ID client ..." | ||
create_client $ADMIN_ACCESS_TOKEN $PRISM_AGENT_CLIENT_ID $PRISM_AGENT_CLIENT_SECRET | ||
fi | ||
{{- if .Values.keycloak.enabled }} | ||
|
||
--- | ||
|
||
apiVersion: v1 | ||
kind: ConfigMap | ||
metadata: | ||
name: prism-agent-realm-import | ||
data: | ||
prism-agent.json: | | ||
{ | ||
"realm": {{ .Values.server.keycloak.realm | quote }}, | ||
"enabled": true | ||
} | ||
{{- end }} |
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
30 changes: 30 additions & 0 deletions
30
infrastructure/charts/agent/templates/stringsecret-agent-keycloak-secret.yaml
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,30 @@ | ||
apiVersion: "secretgenerator.mittwald.de/v1alpha1" | ||
kind: StringSecret | ||
metadata: | ||
name: "agent-keycloak-client-secret" | ||
namespace: {{ .Release.Namespace }} | ||
spec: | ||
forceRegenerate: false | ||
fields: | ||
- fieldName: "secret" | ||
encoding: "base64" | ||
length: "16" | ||
|
||
--- | ||
|
||
apiVersion: "secretgenerator.mittwald.de/v1alpha1" | ||
kind: StringSecret | ||
metadata: | ||
name: "keycloak-admin-secret" | ||
namespace: {{ .Release.Namespace }} | ||
labels: | ||
{{ template "labels.common" . }} | ||
spec: | ||
forceRegenerate: false | ||
fields: | ||
- fieldName: "password" | ||
encoding: "base64" | ||
length: "32" | ||
- fieldName: "postgres-password" | ||
encoding: "base64" | ||
length: "32" |
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