Skip to content

MGMT-23545: Mount pull secret token as a file#2053

Merged
openshift-merge-bot[bot] merged 1 commit intoopenshift:masterfrom
pastequo:feat/mount-secrets-as-file-not-env-vars
Apr 9, 2026
Merged

MGMT-23545: Mount pull secret token as a file#2053
openshift-merge-bot[bot] merged 1 commit intoopenshift:masterfrom
pastequo:feat/mount-secrets-as-file-not-env-vars

Conversation

@pastequo
Copy link
Copy Markdown
Contributor

Mount pull secret token as a file

There is still a fallback to the environment variable in the code that tries to get the value of this secret

@openshift-ci-robot openshift-ci-robot added the jira/valid-reference Indicates that this PR references a valid Jira ticket of any type. label Mar 18, 2026
@openshift-ci-robot
Copy link
Copy Markdown

@pastequo: This pull request references MGMT-23545 which is a valid jira issue.

Warning: The referenced jira issue has an invalid target version for the target branch this PR targets: expected the task to target the "4.22.0" version, but no target version was set.

Details

In response to this:

Mount pull secret token as a file

There is still a fallback to the environment variable in the code that tries to get the value of this secret

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the openshift-eng/jira-lifecycle-plugin repository.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 18, 2026

Important

Review skipped

Auto reviews are limited based on label configuration.

🚫 Review skipped — only excluded labels are configured. (1)
  • do-not-merge/work-in-progress

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 08dda3b1-82dd-4f36-a9b6-493a722450b1

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

Walkthrough

Switched pull-secret delivery from an environment variable to a file-mounted Kubernetes secret. Deployment manifest mounts the secret, the config struct tag no longer binds to PULL_SECRET_TOKEN, startup reads the token from the mounted file (with env fallback) and exits on read errors; parsing tests were added.

Changes

Cohort / File(s) Summary
Deployment Configuration
deploy/assisted-installer-controller/assisted-installer-controller-pod.yaml.template
Removed PULL_SECRET_TOKEN env var; added pull-secret secret-backed volume projecting pull-secret-token as token with mode 0400, mounted at /etc/assisted-installer-controller.
Controller Config Struct
src/assisted_installer_controller/assisted_installer_controller.go
Removed envconfig:"PULL_SECRET_TOKEN" required:"true" tags from ControllerConfig.PullSecretToken, leaving only secret:"true".
Startup / Token Parsing
src/main/assisted-installer-controller/assisted_installer_main.go
Added pullSecretPath = "/etc/assisted-installer-controller/token" constant and parsePullSecretToken(log, path) to read/trim token from file, fall back to PULL_SECRET_TOKEN if file missing, return errors on read failures, assign token into Options.ControllerConfig.PullSecretToken, and log.Fatalf on parse error.
Unit Tests
src/main/assisted-installer-controller/assisted_installer_main_test.go
Added Ginkgo tests for parsePullSecretToken: file-read success, trimming whitespace, env-var fallback when file missing, empty/whitespace file behavior, temp-file helper, and teardown unsetting PULL_SECRET_TOKEN.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

@openshift-ci openshift-ci bot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Mar 18, 2026
@openshift-ci openshift-ci bot requested review from avishayt and romfreiman March 18, 2026 16:38
@openshift-ci openshift-ci bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Mar 18, 2026
Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In
`@deploy/assisted-installer-controller/assisted-installer-controller-pod.yaml.template`:
- Around line 112-114: The secret volume used by the pod (volume with name
"pull-secret" and secretName "assisted-installer-controller-secret") must be
marked optional so parsePullSecretToken() in assisted_installer_main.go can fall
back to the PULL_SECRET_TOKEN env var; update the secret volume definition by
adding optional: true under the secret: block for the "pull-secret" volume to
allow the pod to start when the secret is absent and let parsePullSecretToken()
perform the env fallback.

In `@src/main/assisted-installer-controller/assisted_installer_main.go`:
- Around line 350-354: The parsePullSecretToken function currently returns on
any file read error which prevents falling back to the PULL_SECRET_TOKEN
environment variable; update parsePullSecretToken to only treat a non-existent
file (os.IsNotExist(err)) or empty file content as a trigger to read and return
os.Getenv("PULL_SECRET_TOKEN"), while still returning other read errors (i.e.,
permission or IO errors) immediately; also trim whitespace from the file content
before returning and apply the same fallback logic to the analogous code
handling pull secret parsing around the referenced 361-369 region so both code
paths honor the environment variable when the file is missing or empty.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 54b47abf-28f7-4d81-86c0-7daaeb9ee9ec

📥 Commits

Reviewing files that changed from the base of the PR and between c3de390 and f330bd2.

📒 Files selected for processing (4)
  • deploy/assisted-installer-controller/assisted-installer-controller-pod.yaml.template
  • src/assisted_installer_controller/assisted_installer_controller.go
  • src/main/assisted-installer-controller/assisted_installer_main.go
  • src/main/assisted-installer-controller/assisted_installer_main_test.go

@codecov
Copy link
Copy Markdown

codecov bot commented Mar 18, 2026

Codecov Report

❌ Patch coverage is 60.00000% with 6 lines in your changes missing coverage. Please review.
✅ Project coverage is 48.82%. Comparing base (f388598) to head (48ec42d).
⚠️ Report is 2 commits behind head on master.

Files with missing lines Patch % Lines
...ed-installer-controller/assisted_installer_main.go 60.00% 6 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2053      +/-   ##
==========================================
+ Coverage   48.79%   48.82%   +0.03%     
==========================================
  Files          20       20              
  Lines        4382     4397      +15     
==========================================
+ Hits         2138     2147       +9     
- Misses       2020     2026       +6     
  Partials      224      224              
Files with missing lines Coverage Δ
...taller_controller/assisted_installer_controller.go 77.41% <ø> (ø)
...ed-installer-controller/assisted_installer_main.go 29.10% <60.00%> (+2.66%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@pastequo pastequo force-pushed the feat/mount-secrets-as-file-not-env-vars branch from f330bd2 to 17b2d3a Compare March 18, 2026 17:01
Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

♻️ Duplicate comments (1)
deploy/assisted-installer-controller/assisted-installer-controller-pod.yaml.template (1)

112-114: ⚠️ Potential issue | 🟠 Major

Make the pull-secret volume optional so env fallback can actually execute.

On Line 114, the secret volume is currently mandatory. If the secret is missing, Kubernetes blocks pod startup, so parsePullSecretToken() never reaches its PULL_SECRET_TOKEN fallback path.

Proposed manifest fix
         - name: pull-secret
           secret:
             secretName: assisted-installer-controller-secret
+            optional: true

Use this to verify the mismatch (required volume vs runtime fallback):

#!/bin/bash
set -euo pipefail

echo "== pull-secret volume block =="
sed -n '108,118p' deploy/assisted-installer-controller/assisted-installer-controller-pod.yaml.template

echo
echo "== parsePullSecretToken fallback block =="
sed -n '350,377p' src/main/assisted-installer-controller/assisted_installer_main.go

Expected result: volume block shows no optional: true, while Go code shows fallback when file is missing/empty.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@deploy/assisted-installer-controller/assisted-installer-controller-pod.yaml.template`
around lines 112 - 114, The pull-secret secret volume is currently required
which prevents the pod from starting when the secret is absent and blocks
parsePullSecretToken() from using its PULL_SECRET_TOKEN fallback; update the
manifest's volume entry for the "pull-secret" secretName
assisted-installer-controller-secret to make the secret optional (add optional:
true under the secret block) so the container can start without the secret and
parsePullSecretToken() can execute its runtime fallback logic.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Duplicate comments:
In
`@deploy/assisted-installer-controller/assisted-installer-controller-pod.yaml.template`:
- Around line 112-114: The pull-secret secret volume is currently required which
prevents the pod from starting when the secret is absent and blocks
parsePullSecretToken() from using its PULL_SECRET_TOKEN fallback; update the
manifest's volume entry for the "pull-secret" secretName
assisted-installer-controller-secret to make the secret optional (add optional:
true under the secret block) so the container can start without the secret and
parsePullSecretToken() can execute its runtime fallback logic.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: e6e06692-1eee-4943-80ff-5000d05e662a

📥 Commits

Reviewing files that changed from the base of the PR and between f330bd2 and 17b2d3a.

📒 Files selected for processing (4)
  • deploy/assisted-installer-controller/assisted-installer-controller-pod.yaml.template
  • src/assisted_installer_controller/assisted_installer_controller.go
  • src/main/assisted-installer-controller/assisted_installer_main.go
  • src/main/assisted-installer-controller/assisted_installer_main_test.go
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/assisted_installer_controller/assisted_installer_controller.go
  • src/main/assisted-installer-controller/assisted_installer_main_test.go

@pastequo
Copy link
Copy Markdown
Contributor Author

/hold

@openshift-ci openshift-ci bot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Mar 18, 2026
@pastequo
Copy link
Copy Markdown
Contributor Author

Im holding it because I need to figure out if it's okay to have an empty secret

On my local test (sno) it seems to be the case

@pastequo pastequo force-pushed the feat/mount-secrets-as-file-not-env-vars branch from 17b2d3a to f3bf117 Compare March 19, 2026 08:49
@pastequo
Copy link
Copy Markdown
Contributor Author

/unhold

@openshift-ci openshift-ci bot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Mar 19, 2026
@pastequo
Copy link
Copy Markdown
Contributor Author

/retest

1 similar comment
@pastequo
Copy link
Copy Markdown
Contributor Author

/retest

@pastequo
Copy link
Copy Markdown
Contributor Author

/override ci/prow/edge-e2e-ai-operator-ztp

@openshift-ci
Copy link
Copy Markdown

openshift-ci bot commented Mar 27, 2026

@pastequo: Overrode contexts on behalf of pastequo: ci/prow/edge-e2e-ai-operator-ztp

Details

In response to this:

/override ci/prow/edge-e2e-ai-operator-ztp

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.


if err != nil {
switch {
case os.IsNotExist(err):
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.

So if we have wrong permissions or empty file, we do not fallback to env var? Is this intended?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It's definitively arguable, but I think so. If the user (or something else) didn't configure everything correctly, I would rather fail "fast" instead of trying to make it work. I think it could be misleading for the user

PS empty file is not an error, we can have an empty environment variable today (maybe just for the dev stack tho)

path: /etc/resolv.conf
- name: pull-secret
secret:
secretName: assisted-installer-controller-secret
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.

      items:
      - key: pull-secret-token
        path: token
      defaultMode: 0400

shouldn't we add that? This way we would make sure the key matches at deploy time, the error would be obvious if they doesn't match (not present in the secret). WDYT?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

it shouldn't hurt, I will give a try

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I installed a SNO cluster with my local setup, it was successful even if the token was empty

I analyzed the pod spec, it contains "runAsUser" at the container spec level (and also "fsGroup" at the pod spec level, but it's not used here), so AFAIU it is guarantee that the container will run with that user and that the file will be owned by that user. So 0400 makes sense to me

@pastequo pastequo force-pushed the feat/mount-secrets-as-file-not-env-vars branch from f3bf117 to 9ea2a1f Compare April 8, 2026 09:06
@pastequo pastequo force-pushed the feat/mount-secrets-as-file-not-env-vars branch from 9ea2a1f to 48ec42d Compare April 8, 2026 09:41
@openshift-ci
Copy link
Copy Markdown

openshift-ci bot commented Apr 8, 2026

@pastequo: all tests passed!

Full PR test history. Your PR dashboard.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here.

@rccrdpccl
Copy link
Copy Markdown
Contributor

/lgtm
/approve

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Apr 9, 2026
@openshift-ci
Copy link
Copy Markdown

openshift-ci bot commented Apr 9, 2026

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: pastequo, rccrdpccl

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-merge-bot openshift-merge-bot bot merged commit 5312670 into openshift:master Apr 9, 2026
21 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. jira/valid-reference Indicates that this PR references a valid Jira ticket of any type. lgtm Indicates that a PR is ready to be merged. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants