Skip to content

feat(operator): support private OCI registry credentials for platform source - #2472

Merged
Aleksei Sviridkin (lexfrei) merged 2 commits into
mainfrom
feat/platform-source-credentials
Jun 25, 2026
Merged

Aleksei Sviridkin (lexfrei) merged 2 commits into
mainfrom
feat/platform-source-credentials

Conversation

@IvanHunters

@IvanHunters IvanHunters commented Apr 23, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Implements support for private OCI registry and Git repository credentials in platform sources. Adds --platform-source-secret flag to the operator and corresponding Helm chart parameter.

Closes #2455

Changes

Operator (cmd/cozystack-operator/main.go)

  • Added --platform-source-secret flag for specifying Secret name
  • Updated generateOCIRepository() to set spec.secretRef when secret is provided
  • Updated generateGitRepository() to set spec.secretRef when secret is provided
  • Secret is expected to be in cozy-system namespace

Helm Chart

  • packages/core/installer/values.yaml: Added cozystackOperator.platformSourceSecret parameter with documentation
  • packages/core/installer/templates/cozystack-operator.yaml: Pass --platform-source-secret flag to operator container

Usage Example

For private OCI registry (e.g., GitLab Container Registry):

# Create registry credentials secret
kubectl create secret docker-registry gitlab-registry-creds \
  --namespace cozy-system \
  --docker-server=registry.gitlab.example.com \
  --docker-username=<username> \
  --docker-password=<token>
# Helm values
cozystackOperator:
  platformSourceUrl: 'oci://registry.gitlab.example.com/mygroup/cozystack-packages'
  platformSourceRef: 'tag=v1.0.0'
  platformSourceSecret: 'gitlab-registry-creds'

For private Git repository:

# Create Git credentials secret (SSH key or basic auth)
kubectl create secret generic git-creds \
  --namespace cozy-system \
  --from-literal=username=<username> \
  --from-literal=password=<token>
# Helm values
cozystackOperator:
  platformSourceUrl: 'https://github.com/private-org/cozystack-packages'
  platformSourceRef: 'branch=main'
  platformSourceSecret: 'git-creds'

Testing

Manually verified:

  • OCIRepository resource is created with spec.secretRef when secret name is provided
  • GitRepository resource is created with spec.secretRef when secret name is provided
  • Resources are created without spec.secretRef when secret name is empty (backward compatible)
  • Helm chart renders correctly with and without platformSourceSecret parameter

Checklist

Release note

feat(operator): add `--platform-source-secret` flag to authenticate the platform package source against private OCI registries (kubernetes.io/dockerconfigjson) and private Git repositories (basic-auth, bearer token, or SSH key). Empty value preserves existing public-registry behaviour.

Summary by CodeRabbit

  • New Features

    • Added support for configuring a Kubernetes Secret for the platform source.
    • Installer settings and startup options now let you provide a secret name for Flux source credentials.
  • Bug Fixes

    • Generated platform source resources can now reference the provided Secret, enabling authenticated access for OCI and Git sources.
  • Documentation

    • Updated configuration docs to explain the new secret setting and required secret format.

@coderabbitai

coderabbitai Bot commented Apr 23, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 7721ddf3-cef9-4893-a9b4-29fcba1103a4

📥 Commits

Reviewing files that changed from the base of the PR and between 29bf56f and fff9e82.

📒 Files selected for processing (5)
  • cmd/cozystack-operator/main.go
  • cmd/cozystack-operator/main_test.go
  • go.mod
  • packages/core/installer/templates/cozystack-operator.yaml
  • packages/core/installer/values.yaml

📝 Walkthrough

Walkthrough

Adds a platformSourceSecret installer value and CLI flag, threads the secret name through operator startup, and sets spec.secretRef on generated Flux OCIRepository and GitRepository resources. Tests cover empty and populated secret references.

Changes

Platform source secret wiring

Layer / File(s) Summary
Installer value and arg wiring
packages/core/installer/values.yaml, packages/core/installer/templates/cozystack-operator.yaml
Adds cozystackOperator.platformSourceSecret and conditionally appends --platform-source-secret to the operator container args.
Operator flag and startup plumbing
cmd/cozystack-operator/main.go
Adds --platform-source-secret, threads the secret name through startup logging and installPlatformSourceResource, and passes it into source-type selection.
Flux source secretRef generation
cmd/cozystack-operator/main.go, go.mod
Updates generateOCIRepository and generateGitRepository to set spec.secretRef when a secret name is provided, and adds the Flux metadata package as a direct dependency.
Repository-generation tests
cmd/cozystack-operator/main_test.go
Adjusts OCI/Git generation tests for the new parameter and adds coverage for empty and populated SecretRef values.

Sequence Diagram(s)

sequenceDiagram
  participant Template as cozystack-operator.yaml template
  participant Main as cozystack-operator main
  participant Install as installPlatformSourceResource
  participant OCI as generateOCIRepository
  participant Git as generateGitRepository
  participant FluxOCI as OCIRepository
  participant FluxGit as GitRepository

  Template->>Main: --platform-source-secret
  Main->>Install: platformSourceSecret
  alt platformSourceUrl is OCI
    Install->>OCI: secretName
    OCI->>FluxOCI: set spec.secretRef
  else platformSourceUrl is Git
    Install->>Git: secretName
    Git->>FluxGit: set spec.secretRef
  end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 I found a secret in the clover glow,
and tucked it where Flux can know.
OCI hops, Git hops, both set right,
cozy charts and operator in sync tonight,
thump-thump — the burrow’s credentials flow.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 30.77% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title matches the main change: adding platform source credential support for private OCI registries.
Linked Issues check ✅ Passed The PR implements the requested platform-source secret flag and wires it into OCIRepository, GitRepository, and Helm values.
Out of Scope Changes check ✅ Passed The changed files and tests stay focused on platform source credential support, with no clear unrelated additions.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/platform-source-credentials

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NOT LGTM — the operator binary and its unit tests do not compile in their current state; both are blockers.

This adds a --platform-source-secret flag so the operator attaches spec.secretRef to the generated OCIRepository/GitRepository, enabling a private platform source.

On the secret-handling concerns: the design is sound. The operator only references the secret by name (it never reads the credentials, and only the name — not any secret content — is logged); the credentials are consumed by the Flux source-controller under its existing RBAC, so no new operator RBAC is required; and the empty default leaves existing public-registry installs unchanged. The blockers below are compile-level, not security-level.

Blockers

  1. The operator does not compile. metav1.LocalObjectReference does not exist in k8s.io/apimachinery/pkg/apis/meta/v1. The Flux SecretRef field is typed *meta.LocalObjectReference from github.com/fluxcd/pkg/apis/meta, so neither metav1 nor the already-imported corev1.LocalObjectReference satisfies it — import github.com/fluxcd/pkg/apis/meta and use &meta.LocalObjectReference{Name: secretName}. go build ./cmd/cozystack-operator fails with undefined: metav1.LocalObjectReference. Evidence: cmd/cozystack-operator/main.go:545 and cmd/cozystack-operator/main.go:587.

  2. The unit tests do not compile. generateOCIRepository and generateGitRepository gained a required secretName parameter, but the existing test callers still pass three arguments, so go test ./cmd/cozystack-operator fails with "not enough arguments". No test covers the new secretRef behavior either. Evidence: new signatures at cmd/cozystack-operator/main.go:513 and main.go:554; unchanged 3-argument callers at cmd/cozystack-operator/main_test.go:490, :516, :526 (OCI) and :534, :560, :570 (Git).

Non-blocking

  1. The credential-format guidance is wrong for Git sources. The value comment and the flag help both state the secret is kubernetes.io/dockerconfigjson type, but a GitRepository source authenticates with basic-auth (username/password) or SSH (identity/known_hosts) secrets — a dockerconfigjson secret will fail Git authentication. The PR description itself uses kubectl create secret generic for the Git example, contradicting the inline docs. Document the OCI and Git secret formats separately. Evidence: packages/core/installer/values.yaml:7-9 and cmd/cozystack-operator/main.go:114.

… source

Added --platform-source-secret flag to cozystack-operator that allows
specifying a Secret name for registry authentication. This enables using
private OCI registries and Git repositories as platform sources.

Changes:
- cmd/cozystack-operator/main.go:
  - Add --platform-source-secret flag
  - Pass secretName to generateOCIRepository() and generateGitRepository()
  - Set spec.secretRef in generated resources when secret is specified

- packages/core/installer/values.yaml:
  - Add cozystackOperator.platformSourceSecret parameter

- packages/core/installer/templates/cozystack-operator.yaml:
  - Pass --platform-source-secret flag to operator container

Usage:
1. Create registry credentials secret in cozy-system namespace:
   kubectl create secret docker-registry my-registry-creds \
     --namespace cozy-system \
     --docker-server=registry.example.com \
     --docker-username=user \
     --docker-password=token

2. Configure Helm values:
   cozystackOperator:
     platformSourceUrl: 'oci://registry.example.com/repo/packages'
     platformSourceSecret: 'my-registry-creds'

Closes #2455

Signed-off-by: IvanHunters <[email protected]>
@IvanHunters
IvanHunters force-pushed the feat/platform-source-credentials branch from 28a8029 to 0427b18 Compare June 24, 2026 20:08
@github-actions github-actions Bot added area/uncategorized PR auto-labeler could not map title scope to a known area/*; please review kind/feature Categorizes issue or PR as related to a new feature size/M This PR changes 30-99 lines, ignoring generated files labels Jun 24, 2026
- Run `go mod tidy` to move github.com/fluxcd/pkg/apis/meta from
  indirect to direct require: it became a direct import after the
  SecretRef type fix.
- Refine the --platform-source-secret flag docstring and the matching
  values.yaml comment: drop identity.pub from the SSH required-keys
  list (Flux source-controller only consumes identity + known_hosts)
  and mention bearerToken as an alternative to username+password for
  Git over HTTPS.
- Note in values.yaml that the Secret must exist in cozy-system before
  the operator reconciles; otherwise source-controller reports a
  failed condition until the Secret is created.

Signed-off-by: Ivan Okhotnikov <[email protected]>
@IvanHunters
IvanHunters marked this pull request as ready for review June 24, 2026 20:29
@dosubot dosubot Bot added the area/platform Issues or PRs related to platform infrastructure (bundle, flux, talos, installer) label Jun 24, 2026
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request enables authentication for platform sources by allowing users to specify a Kubernetes Secret containing credentials for private OCI or Git repositories. This change ensures that the operator can securely fetch packages from private sources while maintaining backward compatibility for public registries.

Highlights

  • Authentication Support: Added support for private OCI registries and Git repositories by introducing a new --platform-source-secret flag.
  • Operator Updates: Updated the operator to propagate the secret reference to generated OCIRepository and GitRepository resources.
  • Helm Configuration: Exposed the platformSourceSecret parameter in the Helm chart to allow users to configure credentials via values.
New Features

🧠 You can now enable Memory (public preview) to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment Gemini (@gemini-code-assist) Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize the Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counterproductive. You can react with 👍 and 👎 on Gemini (@gemini-code-assist) comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a new --platform-source-secret command-line flag to the cozystack-operator to support private platform sources. When specified, this secret is set as the spec.secretRef on the generated Flux OCIRepository or GitRepository resources. The changes include updating the operator's main logic, adding corresponding unit tests, updating the Helm chart templates and values.yaml to expose this option, and promoting the github.com/fluxcd/pkg/apis/meta dependency to a direct requirement in go.mod. There are no review comments, and we have no feedback to provide.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM — all three findings from the prior review are fixed and verified (build, tests, vet, helm render all clean); the dual-model pass surfaced no new blockers.

Business context: enable a private OCI registry or Git repo as the platform source by attaching spec.secretRef to the generated Flux OCIRepository/GitRepository (closes #2455).

Verified against the current head:

  • Compilation fixed — now imports github.com/fluxcd/pkg/apis/meta and sets &fluxmeta.LocalObjectReference{Name: secretName}; go build ./cmd/cozystack-operator passes.
  • Tests fixed and extended — all callers updated to the 4-arg signature, plus new _WithSecret cases and nil assertions for the empty-secret path on both OCI and Git; go test ./cmd/cozystack-operator passes.
  • Secret-type guidance corrected — values.yaml and the flag help now document the OCI (kubernetes.io/dockerconfigjson), Git-over-HTTPS (username+password or bearerToken), and Git-over-SSH (identity + known_hosts) formats separately, matching the upstream source-controller CRD.

Also confirmed: go vet/gofmt/go mod tidy clean, go.mod correctly promotes the meta package to a direct dependency, the installer chart renders the flag only when the value is non-empty (backward compatible), and the secret namespace (cozy-system) matches where the source resource is created.

@lexfrei
Aleksei Sviridkin (lexfrei) merged commit 4593b72 into main Jun 25, 2026
16 checks passed
@lexfrei
Aleksei Sviridkin (lexfrei) deleted the feat/platform-source-credentials branch June 25, 2026 11:41
IvanHunters added a commit to IvanHunters/community that referenced this pull request Jul 8, 2026
Move private-repository credential handling off a proposed
PackageSourceRef.secretRef field and onto the Flux source created at
tap time, matching the merged cozystack/cozystack#2472 pattern: the
PackageSource reconciler only reads SourceRef to build the
ArtifactGenerator and never creates the source, so the field would have
had no reconcile path. Derive marketplace state from PackageSource plus
ApplicationDefinition rather than a new marketplace.yaml, and align tap
and untap semantics, the community index, and the validation reuse with
community#12. No CRD change and no migration.

Signed-off-by: IvanHunters <[email protected]>
IvanHunters added a commit to cozystack/community that referenced this pull request Aug 24, 2026
Move private-repository credential handling off a proposed
PackageSourceRef.secretRef field and onto the Flux source created at
tap time, matching the merged cozystack/cozystack#2472 pattern: the
PackageSource reconciler only reads SourceRef to build the
ArtifactGenerator and never creates the source, so the field would have
had no reconcile path. Derive marketplace state from PackageSource plus
ApplicationDefinition rather than a new marketplace.yaml, and align tap
and untap semantics, the community index, and the validation reuse with
community#12. No CRD change and no migration.

Signed-off-by: IvanHunters <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/platform Issues or PRs related to platform infrastructure (bundle, flux, talos, installer) area/uncategorized PR auto-labeler could not map title scope to a known area/*; please review kind/feature Categorizes issue or PR as related to a new feature size/M This PR changes 30-99 lines, ignoring generated files

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support private OCI registry credentials for platform source

2 participants