OAuth2 configuration example #705

Open
opened 2024-08-05 16:57:33 +00:00 by limiting-factor · 10 comments

I would like to configure https://code.forgejo.org/f3/f3-forgejo/raw/branch/main/helm/a.yml so that it allows registration from code.forgejo.org.

https://code.forgejo.org/forgejo-helm/forgejo-helm#oauth2-settings

I think I should do something like:

gitea:
  oauth:
    - name: 'code-forgejo-org'
      provider: 'openidConnect'
      key: 'hello'
      secret: 'world'
      autoDiscoverUrl: 'https://code.forgejo.org/.well-known/openid-configuration'
      #useCustomUrls:
      #customAuthUrl:
      #customTokenUrl:
      #customProfileUrl:
      #customEmailUrl:

What I'm not sure about is where I should get key and secret? https://forgejo.org/docs/latest/admin/oauth2-provider/ does not seem to document that. https://forgejo.org/docs/latest/user/oauth2-provider/ looks more relevant and the example at https://forgejo.org/docs/latest/user/oauth2-provider/#examples is what I think is good for that.

But ... should I really do that with a user that I create myself? Isn't it better if an admin of code.forgejo.org does it instead?

I would like to configure https://code.forgejo.org/f3/f3-forgejo/raw/branch/main/helm/a.yml so that it allows registration from code.forgejo.org. https://code.forgejo.org/forgejo-helm/forgejo-helm#oauth2-settings I think I should do something like: ```yaml gitea: oauth: - name: 'code-forgejo-org' provider: 'openidConnect' key: 'hello' secret: 'world' autoDiscoverUrl: 'https://code.forgejo.org/.well-known/openid-configuration' #useCustomUrls: #customAuthUrl: #customTokenUrl: #customProfileUrl: #customEmailUrl: ``` What I'm not sure about is where I should get `key` and `secret`? https://forgejo.org/docs/latest/admin/oauth2-provider/ does not seem to document that. https://forgejo.org/docs/latest/user/oauth2-provider/ looks more relevant and the example at https://forgejo.org/docs/latest/user/oauth2-provider/#examples is what I think is good for that. But ... should I really do that with a user that I create myself? Isn't it better if an admin of code.forgejo.org does it instead?
Author

Also, how can the icon be set?

Icon URL: https://design.codeberg.org/logo-kit/icon.svg

Also, how can the icon be set? > Icon URL: https://design.codeberg.org/logo-kit/icon.svg
Contributor

An alternative is to follow the steps manually as explained in the documentation. But it would be interesting to do that with the Helm itself for automation.

An alternative is to follow the steps manually as explained in the documentation. But it would be interesting to do that with the Helm itself for automation.
Owner

https://code.forgejo.org/forgejo-helm/forgejo-helm#oauth2-settings

you should create a kubernetes secret manually and reference it from the yaml via existingSecret

https://code.forgejo.org/forgejo-helm/forgejo-helm#oauth2-settings you should create a kubernetes secret manually and reference it from the yaml via `existingSecret`
Owner

the oauth settings will be configured via gitea admin auth add-oauth and gitea admin auth update-oauth

https://forgejo.org/docs/latest/admin/command-line/#admin-auth-add-oauth

so you need to the proper option names freom the cli without the -- prefix.

if [[ -z "${AUTH_ID}" ]]; then
echo "No oauth configuration found with name '${OAUTH_NAME}'. Installing it now..."
gitea admin auth add-oauth {{- include "gitea.oauth_settings" (list $idx $value) | indent 1 }}
echo '...installed.'
else
echo "Existing oauth configuration with name '${OAUTH_NAME}': '${AUTH_ID}'. Running update to sync settings..."
gitea admin auth update-oauth --id "${AUTH_ID}" {{- include "gitea.oauth_settings" (list $idx $value) | indent 1 }}
echo '...sync settings done.'
fi


Lines 183 to 208 in 949431e
{{- define "gitea.oauth_settings" -}}
{{- $idx := index . 0 }}
{{- $values := index . 1 }}
{{- if not (hasKey $values "key") -}}
{{- $_ := set $values "key" (printf "${GITEA_OAUTH_KEY_%d}" $idx) -}}
{{- end -}}
{{- if not (hasKey $values "secret") -}}
{{- $_ := set $values "secret" (printf "${GITEA_OAUTH_SECRET_%d}" $idx) -}}
{{- end -}}
{{- range $key, $val := $values -}}
{{- if ne $key "existingSecret" -}}
{{- printf "--%s %s " ($key | kebabcase) ($val | quote) -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- define "gitea.public_protocol" -}}
{{- if and .Values.ingress.enabled (gt (len .Values.ingress.tls) 0) -}}
https
{{- else -}}
{{ .Values.gitea.config.server.PROTOCOL }}
{{- end -}}
{{- end -}}

the oauth settings will be configured via `gitea admin auth add-oauth` and `gitea admin auth update-oauth` https://forgejo.org/docs/latest/admin/command-line/#admin-auth-add-oauth so you need to the proper option names freom the cli without the `--` prefix. https://code.forgejo.org/forgejo-helm/forgejo-helm/src/commit/949431ec59cad2488287b52794e752de429b5f1f/templates/gitea/init.yaml#L210-L218 https://code.forgejo.org/forgejo-helm/forgejo-helm/src/commit/949431ec59cad2488287b52794e752de429b5f1f/templates/_helpers.tpl#L183-L208
Owner

so something like this (you can use caml-case, it will be converted automatically)

gitea:
  oauth:
    - name: 'code-forgejo-org'
      provider: 'openidConnect'
      key: 'hello' # Client ID
      secret: 'world' # Client Secret
      autoDiscoverUrl: 'https://code.forgejo.org/.well-known/openid-configuration'
      iconUrl: https://code.forgejo.org/...
      #useCustomUrls:
      #customAuthUrl:
      #customTokenUrl:
      #customProfileUrl:
      #customEmailUrl:
so something like this (you can use caml-case, it will be converted automatically) ```yaml gitea: oauth: - name: 'code-forgejo-org' provider: 'openidConnect' key: 'hello' # Client ID secret: 'world' # Client Secret autoDiscoverUrl: 'https://code.forgejo.org/.well-known/openid-configuration' iconUrl: https://code.forgejo.org/... #useCustomUrls: #customAuthUrl: #customTokenUrl: #customProfileUrl: #customEmailUrl: ```
Owner

you need to create an oauth application

https://code.forgejo.org/user/settings/applications

@earl-warren i can also configure a new app on our forgejo org at https://codeberg.org/org/forgejo/settings/applications

you need to create an oauth application https://code.forgejo.org/user/settings/applications @earl-warren i can also configure a new app on our forgejo org at https://codeberg.org/org/forgejo/settings/applications

There's one flag that I can't quite wrap my head around how to use it: --skip-local-2fa. It doesn't take a value, so how does one provide it through the Helm chart?

There's one flag that I can't quite wrap my head around how to use it: `--skip-local-2fa`. It doesn't take a value, so how does one provide it through the Helm chart?
Owner

@kernald wrote in #705 (comment):

There's one flag that I can't quite wrap my head around how to use it: --skip-local-2fa. It doesn't take a value, so how does one provide it through the Helm chart?

skipLocal-2fa: true

or

skip-local-2fa: true

The chart is smart enough to know it's a flag option

@kernald wrote in https://code.forgejo.org/forgejo-helm/forgejo-helm/issues/705#issuecomment-74433: > There's one flag that I can't quite wrap my head around how to use it: `--skip-local-2fa`. It doesn't take a value, so how does one provide it through the Helm chart? https://code.forgejo.org/forgejo-helm/forgejo-helm/src/commit/f11bfd37546ad3e5850af95b2794c3ccd1dded28/unittests/init/oauth.yaml#L20 or https://code.forgejo.org/forgejo-helm/forgejo-helm/src/commit/f11bfd37546ad3e5850af95b2794c3ccd1dded28/unittests/init/oauth.yaml#L40 The chart is smart enough to know it's a flag option
Owner

@limiting-factor are you still interested to configure oauth on f3 test instance? i can do that for you, especially configure the secret in a k8s secret

@limiting-factor are you still interested to configure oauth on f3 test instance? i can do that for you, especially configure the secret in a k8s secret
Author

I'm good with that, feel free to experiment with it. Until the end of next week I'll only use a local instance for F3 development and will not be disturbed if a.forgefriends.org is down.

I'm good with that, feel free to experiment with it. Until the end of next week I'll only use a local instance for F3 development and will not be disturbed if a.forgefriends.org is down.
Sign in to join this conversation.
No milestone
No assignees
4 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
forgejo-helm/forgejo-helm#705
No description provided.