Skip to content

feat(git): configure GIT_PROVIDERS and clone GIT_REPOSITORIES at init - #444

Merged
fcomte merged 4 commits into
mainfrom
feat/git-providers
Nov 21, 2026
Merged

fcomte merged 4 commits into
mainfrom
feat/git-providers

Conversation

@ddecrulle

@ddecrulle ddecrulle commented Nov 5, 2026 •

Copy link
Copy Markdown
Member

Onyxia's Git integration (InseeFrLab/onyxia#1097) moves from one forge and one token to a list of forges (git.providers in the xOnyxia context), each with its commit identity and its credentials: a token or OAuth. This teaches onyxia-init.sh to configure them, from a new GIT_PROVIDERS variable holding that list as JSON.

It also clones every repository of a new GIT_REPOSITORIES variable: the repositories picked in the Onyxia launcher (git.repositories of the chart values), each with its branch.

Without GIT_PROVIDERS and GIT_REPOSITORIES nothing changes: existing charts and Onyxia versions keep the current behavior.

What it does, per entry

Configuration
Identity includeIf "hasconfig:remote.*.url:<url>/**": commits use the identity of the forge of the repository, GIT_USER_NAME/GIT_USER_MAIL remain the default
credentials.type: "token" git-credential-store, scoped to the forge (credential.<origin>.helper)
credentials.type: "oauth" git-credential-oauth behind git-credential-cache. Added to base, pinned and verified like the other tools

For these forges the clone no longer puts a token in the URL: it ended up in plain text in .git/config, in the project directory, and would be outdated after a refresh. The former path remains for repositories on a forge that isn't listed.

Resulting configuration

With one forge per kind of credentials: OAuth with device flow (GitLab), OAuth without it (Forgejo), device flow only (GitHub) and a token (Bitbucket). This is the expected content of the new test in base/tests.yaml, which compares it with what onyxia-init.sh generates.

GIT_PROVIDERS used here
[
{"id": "gitlab", "url": "https://gitlab.example.fr", "user": {"name": "Jane Doe", "email": "jane.doe@example.fr"},
 "credentials": {"type": "oauth", "clientId": "CLIENT_ID_GITLAB", "scopes": ["read_repository", "write_repository"],
  "authorizationUrl": "https://gitlab.example.fr/oauth/authorize", "tokenUrl": "https://gitlab.example.fr/oauth/token",
  "deviceAuthorizationUrl": "https://gitlab.example.fr/oauth/authorize_device", "refreshToken": "REFRESH_TOKEN_GITLAB"}},
{"id": "github", "url": "https://github.com", "user": {"name": "jdoe", "email": "jdoe@users.noreply.github.com"},
 "credentials": {"type": "oauth", "clientId": "CLIENT_ID_GITHUB", "scopes": ["repo"],
  "authorizationUrl": "https://github.com/login/oauth/authorize", "tokenUrl": "https://github.com/login/oauth/access_token",
  "deviceAuthorizationUrl": "https://github.com/login/device/code"}},
{"id": "forgejo", "url": "https://forge.example.org", "user": {"name": "Jane D.", "email": "jane@example.org"},
 "credentials": {"type": "oauth", "clientId": "CLIENT_ID_FORGEJO", "scopes": ["write:repository"],
  "authorizationUrl": "https://forge.example.org/login/oauth/authorize", "tokenUrl": "https://forge.example.org/login/oauth/access_token",
  "refreshToken": "REFRESH_TOKEN_FORGEJO"}},
{"id": "bitbucket", "url": "https://bitbucket.org", "user": {"name": "Jane Doe", "email": "jane.doe@example.fr"},
 "credentials": {"type": "token", "username": "x-bitbucket-api-token-auth", "token": "TOKEN_BITBUCKET"}}
]

GIT_USER_NAME, GIT_USER_MAIL and GIT_CREDENTIALS_CACHE_DURATION=0 are also set.

~/.gitconfig

[user]
	name = Jane Doe
	email = jane.doe@example.fr
[credential]
	helper = cache --timeout=0
[includeIf "hasconfig:remote.*.url:https://gitlab.example.fr/**"]
	path = /home/onyxia/.gitconfig-onyxia-gitlab
[credential "https://gitlab.example.fr"]
	helper = 
	oauthClientId = CLIENT_ID_GITLAB
	oauthScopes = read_repository write_repository
	oauthAuthURL = https://gitlab.example.fr/oauth/authorize
	oauthTokenURL = https://gitlab.example.fr/oauth/token
	helper = cache --timeout=31536000
	oauthDeviceAuthURL = https://gitlab.example.fr/oauth/authorize_device
	helper = !timeout 300 git credential-oauth -device
[includeIf "hasconfig:remote.*.url:https://forge.example.org/**"]
	path = /home/onyxia/.gitconfig-onyxia-forgejo
[credential "https://forge.example.org"]
	helper = 
	oauthClientId = CLIENT_ID_FORGEJO
	oauthScopes = write:repository
	oauthAuthURL = https://forge.example.org/login/oauth/authorize
	oauthTokenURL = https://forge.example.org/login/oauth/access_token
	helper = cache --timeout=31536000
	helper = !timeout 30 git credential-oauth
[includeIf "hasconfig:remote.*.url:https://bitbucket.org/**"]
	path = /home/onyxia/.gitconfig-onyxia-bitbucket
[credential "https://bitbucket.org"]
	helper = 
	helper = store
[includeIf "hasconfig:remote.*.url:https://github.com/**"]
	path = /home/onyxia/.gitconfig-onyxia-github
[credential "https://github.com"]
	helper = 
	oauthClientId = CLIENT_ID_GITHUB
	oauthScopes = repo
	oauthAuthURL = https://github.com/login/oauth/authorize
	oauthTokenURL = https://github.com/login/oauth/access_token
	helper = cache --timeout=31536000
	oauthDeviceAuthURL = https://github.com/login/device/code
	helper = !timeout 300 git credential-oauth -device
[pull]
	rebase = false

~/.gitconfig-onyxia-forgejo

[user]
	name = Jane D.
	email = jane@example.org

~/.git-credentials (mode 600)

https://x-bitbucket-api-token-auth:TOKEN_BITBUCKET@bitbucket.org

How to read it:

  • helper = (empty) isn't a mistake: it drops the helpers declared so far for this forge, so that the global cache --timeout=0 can't evict the refresh token.
  • Helpers are tried in order: the cache first, then git-credential-oauth when the token is missing or expired.
  • The refresh tokens are in none of these files, only in the memory of the cache daemon.
  • GitHub comes last since device-flow-only forges are configured after the clone.

Repositories (GIT_REPOSITORIES)

[{"providerId": "gitlab", "url": "https://gitlab.example.fr/jane/project.git", "branch": "dev"},
 {"providerId": "github", "url": "https://github.com/jane/other", "branch": ""}]
  • Each one is cloned in ROOT_PROJECT_DIRECTORY, on its branch (an empty one clones the default branch). providerId is ignored: git picks the credentials from the URL.
  • A failed clone is logged and the startup goes on with the next one.
  • No token goes in the URL, even for a forge that isn't in GIT_PROVIDERS: the token of GIT_PERSONAL_ACCESS_TOKEN belongs to one forge and would be sent to all of them.
  • Without it, or with an empty array, GIT_REPOSITORY/GIT_BRANCH are used as before. The charts set them to the first repository, for what still reads them (asCodeServerRoot, the RStudio project).

Choices worth a review

  • Seeding the refresh token. git-credential-store can't keep it, so it goes in the cache daemon, with an expired password: git discards the password and hands the refresh token to git-credential-oauth. This goes straight to the helper since git credential approve ignores expired credentials.
  • timeout around git-credential-oauth. When the refresh fails it falls back on an interactive flow and waits with no limit (<-queries, no deadline), which would hang the startup or a git pull: 30 s without device flow (a browser flow can't succeed from a service), 300 s with it.
  • Device-flow-only providers are configured after the clone. Nobody can enter a code during startup. A private repository then fails right away, and the user can clone it from a terminal.
  • Root (RStudio). The files and the cache daemon are created as the user through sudo -u, otherwise a root daemon would hold the user's credentials.
  • unset GIT_PROVIDERS before starting the service: its processes don't need these secrets.
  • The former credential.helper (GIT_CREDENTIALS_CACHE_DURATION) is reset per forge, its short timeout would evict the refresh token.

Known limits

  • The cache is in memory. After a container restart the refresh token of the Secret has usually been rotated: on forges that rotate them, git needs a new authorization (device flow if available), or a new launch of the service.
  • expirationTime of a scoped token isn't used: past this date git gets a 401 and the user has to relaunch the service.
  • With PATH_TO_CA_BUNDLE, git-credential-oauth (Go) only trusts the system store: a CA that isn't in it would make the token endpoint calls fail. Not handled here.

Before merging

Draft because the contract isn't settled on the other side:

  • No change is needed in the charts: an Onyxia instance injects GIT_PROVIDERS and GIT_REPOSITORIES through its schema overrides, ide/git.json (git.providers, git.repositories) and ide/extraenv.json. extraEnvVars values go through tpl, so the chart serializes them with toJson.
  • InseeFrLab/onyxia#1097 is still a draft too.

Test plan

base/tests.yaml now checks the generated configuration (above), the secrets staying out of the files and of the service's environment, and the identity per forge. Images aren't built on PRs, so this runs in the main workflow. I ran the full file locally with container-structure-test (14/14) on inseefrlab/onyxia-base:latest with this PR's scripts added, and checked that altering the script makes the new test fail.

For what needs a forge, I also ran the real onyxia-init.sh in inseefrlab/onyxia-base:latest (git 2.56, amd64 under emulation) with the new install script, against fake forges (git http-backend behind Basic auth, OAuth token endpoint with rotation). The harness isn't part of this PR.

  • Non-root and root: clone through the helper, no secret in .git/config or .gitconfig, ~/.git-credentials in 600, files and daemon owned by the user
  • Commit identity of the forge in the clone, default identity elsewhere; push with the cached access token; token forge with its username
  • Expired access token: refreshed with the rotated token (R1 then R2, never replayed)
  • GIT_CREDENTIALS_CACHE_DURATION=0 doesn't evict the refresh token
  • Legacy without GIT_PROVIDERS, and repository on an unlisted forge: as before
  • Rejected refresh token, no device flow: startup continues after the 30 s limit
  • Device flow only, private repository: no wait at startup, helper in place afterwards
  • Invalid GIT_PROVIDERS, provider without credentials
  • shellcheck --severity=warning
  • GIT_REPOSITORIES: the clone block run against local bare repositories (several repositories and branches, a missing one, an empty array, invalid JSON, nothing set). The new test in base/tests.yaml hasn't run in a container yet
  • Against real GitLab, Forgejo and GitHub instances, and in a real pod
  • Device flow completed end to end (only its configuration is covered)
  • hadolint: to be covered by CI (it couldn't be installed locally)
  • A full build of the base image: the local run added the changes on top of the published image

🤖 Generated with Claude Code

ddecrulle and others added 4 commits November 5, 2026 11:41
Onyxia now gives the services a list of Git forges (git.providers in the
context), with a commit identity and credentials per forge. Support it, as
JSON in GIT_PROVIDERS:

- Commit identity per forge (includeIf hasconfig:remote.*.url).
- Tokens in git-credential-store, scoped to the forge.
- OAuth with git-credential-oauth, added to the base image. The refresh token
  obtained by Onyxia seeds git-credential-cache, which keeps the rotated ones.
- The clone no longer puts a token in the URL for these forges, it would be
  saved in .git/config and outdated once refreshed.

Bounded helpers and the device flow set up after the clone: git-credential-oauth
waits with no limit on an interactive flow, the startup must not hang.

Without GIT_PROVIDERS nothing changes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Runs onyxia-init.sh with one forge per kind of credentials and compares the
generated files with their expected content, which also documents the result.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
GIT_REPOSITORIES holds git.repositories of the chart values, as JSON:
the repositories picked in the Onyxia launcher, each with its branch.
They're all cloned, a failed clone doesn't stop the startup. No token
goes in the URL: the credentials come from GIT_PROVIDERS, the token of
GIT_PERSONAL_ACCESS_TOKEN belongs to one forge and would be sent to all.

Without GIT_REPOSITORIES, or with an empty array, GIT_REPOSITORY and
GIT_BRANCH are used as before.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ddecrulle ddecrulle changed the title feat(git): configure the Git providers of GIT_PROVIDERS at init feat(git): configure GIT_PROVIDERS and clone GIT_REPOSITORIES at init Nov 18, 2026
ddecrulle added a commit to InseeFrLab/helm-charts-dev that referenced this pull request Nov 18, 2026
…t section trimmed

Default image is now inseefrlab/onyxia-vscode-python:py3.13.15-git-providers,
which ships the onyxia-init.sh of InseeFrLab/images-datascience#444
(GIT_PROVIDERS, GIT_REPOSITORIES). The previous tags stay in the list.

The schema no longer exposes the legacy git.enabled/name/email/cache/token
fields to the launcher.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ddecrulle
ddecrulle marked this pull request as ready for review November 20, 2026 14:47
@fcomte
fcomte merged commit d177ed1 into main Nov 21, 2026
1 check passed
@fcomte
fcomte deleted the feat/git-providers branch November 21, 2026 12:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants