Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: sso setup #1026

Merged
merged 2 commits into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions web/kratos/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ RUN apk add gettext
COPY . /usr/bin/app/kratos

RUN mkdir -p /etc/config/kratos && chmod a+x /usr/bin/app/kratos/entrypoint.sh && \
chmod a+x /usr/bin/app/kratos/oidc-setup.sh && \
polaroi8d marked this conversation as resolved.
Show resolved Hide resolved
chown -R 10000:10000 /etc/config/kratos && \
chmod -R 700 /etc/config/kratos

Expand Down
2 changes: 2 additions & 0 deletions web/kratos/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ export OIDC_GOOGLE_SCHEMA_MAPPER
OIDC_AZURE_SCHEMA_MAPPER=$(base64 -w 0 /usr/bin/app/kratos/oidc/azure.schema.jsonnet)
export OIDC_AZURE_SCHEMA_MAPPER

source "/usr/bin/app/kratos/oidc-setup.sh" || exit 1

envsubst '${KRATOS_URL}, ${KRATOS_ADMIN_URL}, ${CRUX_UI_URL}, ${FROM_EMAIL}, ${FROM_NAME}, ${OIDC_GITLABHUB_SCHEMA_MAPPER}, ${OIDC_GOOGLE_SCHEMA_MAPPER}, ${OIDC_AZURE_SCHEMA_MAPPER}' < /usr/bin/app/kratos/kratos.template.yaml > /etc/config/kratos/kratos.yaml

exec kratos $@
48 changes: 0 additions & 48 deletions web/kratos/kratos.template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,54 +15,6 @@ selfservice:
enabled: false
config:
base_redirect_uri: ${KRATOS_URL}
providers:
- id: gitlab
provider: gitlab
mapper_url: "base64://${OIDC_GITLABHUB_SCHEMA_MAPPER}"
auth_url: https://gitlab.com/oauth/authorize
token_url: https://gitlab.com/oauth/token
issuer_url: https://gitlab.com
client_id: ""
client_secret: ""
scope:
- read_user
- openid
- email
- profile
- id: github
provider: github
mapper_url: "base64://${OIDC_GITLABHUB_SCHEMA_MAPPER}"
auth_url: https://github.com/login/oauth/authorize
token_url: https://github.com/login/oauth/access_token
issuer_url: https://github.com
client_id: ""
client_secret: ""
scope:
- read:user
- user:email
- id: google
provider: google
mapper_url: "base64://${OIDC_GOOGLE_SCHEMA_MAPPER}"
auth_url: https://accounts.google.com/o/oauth2/v2/auth
token_url: https://www.googleapis.com/oauth2/v4/token
issuer_url: https://accounts.google.com
client_id: ""
client_secret: ""
scope:
- openid
- email
- profile
- id: azure
provider: microsoft
mapper_url: "base64://${OIDC_AZURE_SCHEMA_MAPPER}"
client_id: ""
client_secret: ""
microsoft_tenant: common
subject_source: userinfo
scope:
- openid
- email
- profile
code:
enabled: true
flows:
Expand Down
104 changes: 104 additions & 0 deletions web/kratos/oidc-setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
#!/usr/bin/env sh
polaroi8d marked this conversation as resolved.
Show resolved Hide resolved
set +eu

[ -z "${OIDC_GILAB_CLIENT_ID:-}" ]
GITLAB_CLIENT_ID_SET=$?
[ -z "${OIDC_GILAB_CLIENT_SECRET-}" ]
GITLAB_CLIENT_SECRET_SET=$?

[ -z "${OIDC_GITHUB_CLIENT_ID-}" ]
GITHUB_CLIENT_ID_SET=$?
[ -z "${OIDC_GITHUB_CLIENT_SECRET-}" ]
GITHUB_CLIENT_SECRET_SET=$?

[ -z "${OIDC_GOOGLE_CLIENT_ID-}" ]
GOOGLE_CLIENT_ID_SET=$?
[ -z "${OIDC_GOOGLE_CLIENT_SECRET-}" ]
GOOGLE_CLIENT_SECRET_SET=$?

[ -z "${OIDC_AZURE_CLIENT_ID-}" ]
AZURE_CLIENT_ID_SET=$?
[ -z "${OIDC_AZURE_CLIENT_SECRET-}" ]
AZURE_CLIENT_SECRET_SET=$?

set -eu

if [ "$GITLAB_CLIENT_ID_SET" -ne "$GITLAB_CLIENT_SECRET_SET" ]
then
echo "OIDC_GILAB_CLIENT_ID or OIDC_GILAB_CLIENT_SECRET not set"
exit 1
fi

if [ "$GITHUB_CLIENT_ID_SET" -ne "$GITHUB_CLIENT_SECRET_SET" ]
then
echo "OIDC_GITHUB_CLIENT_ID or OIDC_GITHUB_CLIENT_SECRET not set"
exit 1
fi

if [ "$GOOGLE_CLIENT_ID_SET" -ne "$GOOGLE_CLIENT_SECRET_SET" ]
then
echo "OIDC_GOOGLE_CLIENT_ID or OIDC_GOOGLE_CLIENT_SECRET not set"
exit 1
fi

if [ "$AZURE_CLIENT_ID_SET" -ne "$AZURE_CLIENT_SECRET_SET" ]
then
echo "OIDC_AZURE_CLIENT_ID or OIDC_AZURE_CLIENT_SECRET not set"
exit 1
fi

PROVIDERS="["

if [[ "$GITLAB_CLIENT_ID_SET" -eq 1 ]] && [[ "$GITLAB_CLIENT_SECRET_SET" -eq 1 ]]
then
if [ -z "${OIDC_GITLABHUB_SCHEMA_MAPPER:-}" ]
then
echo "OIDC_GITLABHUB_SCHEMA_MAPPER missing"
exit 1
fi

PROVIDERS="${PROVIDERS}{\"id\":\"gitlab\",\"provider\":\"gitlab\",\"mapper_url\":\"base64://${OIDC_GITLABHUB_SCHEMA_MAPPER}\",\"client_id\":\"${OIDC_GILAB_CLIENT_ID}\",\"client_secret\":\"${OIDC_GILAB_CLIENT_SECRET}\",\"scope\":[\"read_user\",\"openid\",\"email\",\"profile\"],\"auth_url\":\"https://gitlab.com/oauth/authorize\",\"token_url\":\"https://gitlab.com/oauth/token\",\"issuer_url\":\"https://gitlab.com\"},"
fi

if [[ "$GITHUB_CLIENT_ID_SET" -eq 1 ]] && [[ "$GITHUB_CLIENT_SECRET_SET" -eq 1 ]]
then
if [ -z "${OIDC_GITLABHUB_SCHEMA_MAPPER:-}" ]
then
echo "OIDC_GITLABHUB_SCHEMA_MAPPER missing"
exit 1
fi

PROVIDERS="${PROVIDERS}{\"id\":\"github\",\"provider\":\"github\",\"mapper_url\":\"base64://${OIDC_GITLABHUB_SCHEMA_MAPPER}\",\"client_id\":\"${OIDC_GITHUB_CLIENT_ID}\",\"client_secret\":\"${OIDC_GITHUB_CLIENT_SECRET}\",\"scope\":[\"read:user\",\"user:email\"],\"auth_url\":\"https://github.com/login/oauth/authorize\",\"token_url\":\"https://github.com/login/oauth/access_token\",\"issuer_url\":\"https://github.com\"},"
fi

if [[ "$GOOGLE_CLIENT_ID_SET" -eq 1 ]] && [[ "$GOOGLE_CLIENT_SECRET_SET" -eq 1 ]]
then
if [ -z "${OIDC_GOOGLE_SCHEMA_MAPPER:-}" ]
then
echo "OIDC_GOOGLE_SCHEMA_MAPPER missing"
exit 1
fi

PROVIDERS="${PROVIDERS}{\"id\":\"google\",\"provider\":\"google\",\"mapper_url\":\"base64://${OIDC_GOOGLE_SCHEMA_MAPPER}\",\"client_id\":\"${OIDC_GOOGLE_CLIENT_ID}\",\"client_secret\":\"${OIDC_GOOGLE_CLIENT_SECRET}\",\"scope\":[\"openid\",\"email\",\"profile\"],\"auth_url\":\"https://accounts.google.com/o/oauth2/v2/auth\",\"token_url\":\"https://www.googleapis.com/oauth2/v4/token\",\"issuer_url\":\"https://accounts.google.com\"},"
fi

if [[ "$AZURE_CLIENT_ID_SET" -eq 1 ]] && [[ "$AZURE_CLIENT_SECRET_SET" -eq 1 ]]
then
if [ -z "${OIDC_AZURE_SCHEMA_MAPPER:-}" ]
then
echo "OIDC_AZURE_SCHEMA_MAPPER missing"
exit 1
fi

PROVIDERS="${PROVIDERS}{\"id\":\"azure\",\"provider\":\"microsoft\",\"mapper_url\":\"base64://${OIDC_AZURE_SCHEMA_MAPPER}\",\"client_id\":\"${OIDC_AZURE_CLIENT_ID}\",\"client_secret\":\"${OIDC_AZURE_CLIENT_SECRET}\",\"scope\":[\"openid\",\"email\",\"profile\"],\"microsoft_tenant\":\"common\",\"subject_source\":\"userinfo\"},"
fi

if [[ "${#PROVIDERS}" -gt 1 ]]
then
PROVIDERS="${PROVIDERS::-1}"
export SELFSERVICE_METHODS_OIDC_ENABLED=true
else
unset SELFSERVICE_METHODS_OIDC_ENABLED
fi

export SELFSERVICE_METHODS_OIDC_CONFIG_PROVIDERS="${PROVIDERS}]"
Loading