-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #104 from zitadel/oidc-settings
feat: make oidc settings managable
- Loading branch information
Showing
28 changed files
with
568 additions
and
375 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
FROM golang:1.19-alpine | ||
RUN apk add curl jq | ||
RUN go install github.com/zitadel/[email protected] | ||
COPY setup.sh /setup.sh | ||
RUN chmod +x /setup.sh | ||
ENTRYPOINT [ "/setup.sh" ] |
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,111 @@ | ||
#!/bin/sh | ||
|
||
set -e | ||
|
||
KEY=${KEY:-./machinekey/zitadel-admin-sa.json} | ||
echo "Using key path ${KEY} to the instance admin service account." | ||
|
||
AUDIENCE=${AUDIENCE:-http://localhost:8080} | ||
echo "Using audience ${AUDIENCE} for which the key is used." | ||
|
||
SERVICE=${SERVICE:-$AUDIENCE} | ||
echo "Using the service ${SERVICE} to connect to ZITADEL. For example in docker compose this can differ from the audience." | ||
|
||
AUDIENCE_HOST="$(echo $AUDIENCE | cut -d/ -f3)" | ||
echo "Deferred the Host header ${AUDIENCE_HOST} which will be sent in requests that ZITADEL then maps to a virtual instance" | ||
|
||
JWT=$(zitadel-tools key2jwt --key ${KEY} --audience ${AUDIENCE}) | ||
echo "Created JWT from Admin service account key ${JWT}" | ||
|
||
TOKEN_RESPONSE=$(curl -s --request POST \ | ||
--url ${SERVICE}/oauth/v2/token \ | ||
--header 'Content-Type: application/x-www-form-urlencoded' \ | ||
--header "Host: ${AUDIENCE_HOST}" \ | ||
--data grant_type=urn:ietf:params:oauth:grant-type:jwt-bearer \ | ||
--data scope='openid profile email urn:zitadel:iam:org:project:id:zitadel:aud' \ | ||
--data assertion="${JWT}") | ||
echo "Got response from token endpoint:" | ||
echo "${TOKEN_RESPONSE}" | jq | ||
|
||
TOKEN=$(echo -n ${TOKEN_RESPONSE} | jq --raw-output '.access_token') | ||
echo "Extracted access token ${TOKEN}" | ||
|
||
ORG_RESPONSE=$(curl -s --request GET \ | ||
--url ${SERVICE}/admin/v1/orgs/default \ | ||
--header 'Accept: application/json' \ | ||
--header "Authorization: Bearer ${TOKEN}" \ | ||
--header "Host: ${AUDIENCE_HOST}") | ||
echo "Got default org response:" | ||
echo "${ORG_RESPONSE}" | jq | ||
|
||
ORG_ID=$(echo -n ${ORG_RESPONSE} | jq --raw-output '.org.id') | ||
echo "Extracted default org id ${ORG_ID}" | ||
|
||
HUMAN_USER_USERNAME="[email protected]" | ||
HUMAN_USER_PASSWORD="Password1!" | ||
|
||
HUMAN_USER_PAYLOAD=$(cat << EOM | ||
{ | ||
"userName": "${HUMAN_USER_USERNAME}", | ||
"profile": { | ||
"firstName": "ZITADEL", | ||
"lastName": "Admin", | ||
"displayName": "ZITADEL Admin", | ||
"preferredLanguage": "en" | ||
}, | ||
"email": { | ||
"email": "[email protected]", | ||
"isEmailVerified": true | ||
}, | ||
"password": "${HUMAN_USER_PASSWORD}", | ||
"passwordChangeRequired": false | ||
} | ||
EOM | ||
) | ||
echo "Creating human user" | ||
echo "${HUMAN_USER_PAYLOAD}" | jq | ||
|
||
HUMAN_USER_RESPONSE=$(curl -s --request POST \ | ||
--url ${SERVICE}/management/v1/users/human/_import \ | ||
--header 'Content-Type: application/json' \ | ||
--header 'Accept: application/json' \ | ||
--header "Authorization: Bearer ${TOKEN}" \ | ||
--header "Host: ${AUDIENCE_HOST}" \ | ||
--data-raw "${HUMAN_USER_PAYLOAD}") | ||
echo "Create human user response" | ||
echo "${HUMAN_USER_RESPONSE}" | jq | ||
|
||
if [ "$(echo -n "${HUMAN_USER_RESPONSE}" | jq --raw-output '.code')" == "6" ]; then | ||
echo "admin user already exists" | ||
exit 0 | ||
fi | ||
|
||
HUMAN_USER_ID=$(echo -n ${HUMAN_USER_RESPONSE} | jq --raw-output '.userId') | ||
echo "Extracted human user id ${HUMAN_USER_ID}" | ||
|
||
HUMAN_ADMIN_PAYLOAD=$(cat << EOM | ||
{ | ||
"userId": "${HUMAN_USER_ID}", | ||
"roles": [ | ||
"IAM_OWNER" | ||
] | ||
} | ||
EOM | ||
) | ||
echo "Granting iam owner to human user" | ||
echo "${HUMAN_ADMIN_PAYLOAD}" | jq | ||
|
||
HUMAN_ADMIN_RESPONSE=$(curl -s --request POST \ | ||
--url ${SERVICE}/admin/v1/members \ | ||
--header 'Content-Type: application/json' \ | ||
--header 'Accept: application/json' \ | ||
--header "Authorization: Bearer ${TOKEN}" \ | ||
--header "Host: ${AUDIENCE_HOST}" \ | ||
--data-raw "${HUMAN_ADMIN_PAYLOAD}") | ||
|
||
echo "Grant iam owner to human user response" | ||
echo "${HUMAN_ADMIN_RESPONSE}" | jq | ||
|
||
echo "You can now log in at ${AUDIENCE}/ui/login" | ||
echo "username: ${HUMAN_USER_USERNAME}" | ||
echo "password: ${HUMAN_USER_PASSWORD}" |
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,31 @@ | ||
--- | ||
page_title: "zitadel_default_oidc_settings Data Source - terraform-provider-zitadel" | ||
subcategory: "" | ||
description: |- | ||
Datasource representing the default oidc settings. | ||
--- | ||
|
||
# zitadel_default_oidc_settings (Data Source) | ||
|
||
Datasource representing the default oidc settings. | ||
|
||
## Example Usage | ||
|
||
```terraform | ||
data zitadel_default_oidc_settings oidc_settings {} | ||
output oidc_settings { | ||
value = data.zitadel_default_oidc_settings.oidc_settings | ||
} | ||
``` | ||
|
||
<!-- schema generated by tfplugindocs --> | ||
## Schema | ||
|
||
### Read-Only | ||
|
||
- `access_token_lifetime` (String) lifetime duration of access tokens | ||
- `id` (String) The ID of this resource. | ||
- `id_token_lifetime` (String) lifetime duration of id tokens | ||
- `refresh_token_expiration` (String) expiration duration of refresh tokens | ||
- `refresh_token_idle_expiration` (String) expiration duration of idle refresh tokens |
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,35 @@ | ||
--- | ||
page_title: "zitadel_default_oidc_settings Resource - terraform-provider-zitadel" | ||
subcategory: "" | ||
description: |- | ||
Resource representing the default oidc settings. | ||
--- | ||
|
||
# zitadel_default_oidc_settings (Resource) | ||
|
||
Resource representing the default oidc settings. | ||
|
||
## Example Usage | ||
|
||
```terraform | ||
resource zitadel_default_oidc_settings oidc_settings { | ||
access_token_lifetime = "12h0m0s" | ||
id_token_lifetime = "12h0m0s" | ||
refresh_token_expiration = "720h0m0s" | ||
refresh_token_idle_expiration = "2160h0m0s" | ||
} | ||
``` | ||
|
||
<!-- schema generated by tfplugindocs --> | ||
## Schema | ||
|
||
### Required | ||
|
||
- `access_token_lifetime` (String) lifetime duration of access tokens | ||
- `id_token_lifetime` (String) lifetime duration of id tokens | ||
- `refresh_token_expiration` (String) expiration duration of refresh tokens | ||
- `refresh_token_idle_expiration` (String) expiration duration of idle refresh tokens | ||
|
||
### Read-Only | ||
|
||
- `id` (String) The ID of this resource. |
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,5 @@ | ||
data zitadel_default_oidc_settings oidc_settings {} | ||
|
||
output oidc_settings { | ||
value = data.zitadel_default_oidc_settings.oidc_settings | ||
} |
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,6 @@ | ||
resource zitadel_default_oidc_settings oidc_settings { | ||
access_token_lifetime = "12h0m0s" | ||
id_token_lifetime = "12h0m0s" | ||
refresh_token_expiration = "720h0m0s" | ||
refresh_token_idle_expiration = "2160h0m0s" | ||
} |
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.