Skip to content

Add the manifests and scripts to create a Kubeconfig for OCPCI - #20

Merged
kpouget merged 2 commits into
openshift-psap:mainfrom
kpouget:manifests
Apr 7, 2026
Merged

kpouget merged 2 commits into
openshift-psap:mainfrom
kpouget:manifests

Conversation

@kpouget

@kpouget kpouget commented Apr 3, 2026 •

Copy link
Copy Markdown
Collaborator

Fix: #16

Summary by CodeRabbit

  • New Features
    • Added a utility script to generate kubeconfig files for Kubernetes cluster access with automatic token and certificate retrieval
    • Introduced Kubernetes service account configuration with role-based access control for job management operations

@coderabbitai

coderabbitai Bot commented Apr 3, 2026 •

Copy link
Copy Markdown
📝 Walkthrough

Walkthrough

Adds RBAC configuration and a kubeconfig generation script to establish a service account (ocpci) in the psap-automation namespace with permissions to create, get, list, and watch fournosjobs resources in the fournos.dev API group.

Changes

Cohort / File(s) Summary
Kubeconfig Generation Script
hacks/generate-ocpci-kubeconfig.sh
New bash script that generates a kubeconfig file by reading the current kubectl context, polling for a service account token secret in psap-automation namespace, extracting and decoding the token and CA certificate, then writing a resolved kubeconfig YAML file.
RBAC and ServiceAccount Setup
manifests/ocpci-sa/sa.yaml, manifests/ocpci-sa/role.yaml, manifests/ocpci-sa/rolebinding.yaml, manifests/ocpci-sa/secret.yaml
New Kubernetes manifests defining a ServiceAccount (ocpci), a Role (ocpci-fournos-job-manager) granting create/get/list/watch permissions on fournosjobs resources, a RoleBinding to attach the role to the service account, and a Secret to hold the service account token.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Poem

🐰 A service account hops into place,
With RBAC rules to set the pace,
Four jobs it may create and see,
On OCPCI, now running free!
The kubeconfig script, neat and tight,
Decodes the tokens just right. ✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely summarizes the main change: adding manifests and scripts for OCPCI Kubeconfig creation, matching the changeset's primary objective.
Linked Issues check ✅ Passed The PR successfully implements the core coding requirements from issue #16: creates a ServiceAccount (ocpci) with RBAC Role and RoleBinding allowing create, list, and get verbs for ForgeJobs, and provides a script to generate the kubeconfig file.
Out of Scope Changes check ✅ Passed All changes are directly aligned with issue #16 objectives: ServiceAccount manifests, RBAC configuration for ForgeJobs permissions, and the kubeconfig generation script are all in scope.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

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

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

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 and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
hacks/generate-ocpci-kubeconfig.sh (1)

29-49: Consider restricting kubeconfig file permissions.

The generated kubeconfig contains a sensitive bearer token. While the script writes to a file correctly, it inherits the default umask which may result in world-readable permissions.

🔒 Proposed fix to restrict file permissions
 # Create the kubeconfig
+# Restrict permissions before writing sensitive data
+umask 077
 cat <<EOF > "$OUTPUT_FILE"
 apiVersion: v1
 kind: Config

Alternatively, set permissions after creation:

cat <<EOF > "$OUTPUT_FILE"
...
EOF
chmod 600 "$OUTPUT_FILE"
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@hacks/generate-ocpci-kubeconfig.sh` around lines 29 - 49, The kubeconfig
written to $OUTPUT_FILE contains a sensitive bearer token ($TOKEN) but is
created with default umask, risking world-readable permissions; after creating
the file in the kubeconfig generation block, ensure you restrict its permissions
(for example set mode 0600) so only the owner can read/write the file—apply this
by calling chmod 600 on $OUTPUT_FILE (or set umask appropriately) immediately
after the here-doc that writes the kubeconfig.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@hacks/generate-ocpci-kubeconfig.sh`:
- Around line 17-21: The polling loop using `kubectl get secret "$SECRET_NAME"
-n "$NAMESPACE" -o jsonpath='{.data.token}'` should verify the token is
non-empty and add a timeout; change the loop to repeatedly fetch the token value
and check that the result is not an empty string (not just that `kubectl`
succeeded), track elapsed time or a retry counter (e.g., TIMEOUT or MAX_RETRIES)
and break with a non-zero exit and clear error message if the token is still
empty after the timeout, otherwise proceed when a non-empty token is returned.

---

Nitpick comments:
In `@hacks/generate-ocpci-kubeconfig.sh`:
- Around line 29-49: The kubeconfig written to $OUTPUT_FILE contains a sensitive
bearer token ($TOKEN) but is created with default umask, risking world-readable
permissions; after creating the file in the kubeconfig generation block, ensure
you restrict its permissions (for example set mode 0600) so only the owner can
read/write the file—apply this by calling chmod 600 on $OUTPUT_FILE (or set
umask appropriately) immediately after the here-doc that writes the kubeconfig.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 99a0a1ed-eefd-4ec1-ac29-50aacba995f1

📥 Commits

Reviewing files that changed from the base of the PR and between 00d485f and d219a33.

📒 Files selected for processing (5)
  • hacks/generate-ocpci-kubeconfig.sh
  • manifests/ocpci-sa/role.yaml
  • manifests/ocpci-sa/rolebinding.yaml
  • manifests/ocpci-sa/sa.yaml
  • manifests/ocpci-sa/secret.yaml

Comment on lines +17 to +21
# Wait for the secret to be populated with the token
echo "Waiting for secret $SECRET_NAME to be populated..."
until kubectl get secret "$SECRET_NAME" -n "$NAMESPACE" -o jsonpath='{.data.token}' &> /dev/null; do
sleep 1
done

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Polling loop may pass with empty token.

The current check only verifies the kubectl command succeeds, not that the token is actually populated. If the secret exists but the token field is empty (or not yet populated by the token controller), jsonpath returns an empty string with exit code 0, and the loop exits prematurely.

Additionally, there's no timeout, so the script could wait indefinitely if the secret is never populated.

🔧 Proposed fix with proper token check and timeout
 # Wait for the secret to be populated with the token
 echo "Waiting for secret $SECRET_NAME to be populated..."
-until kubectl get secret "$SECRET_NAME" -n "$NAMESPACE" -o jsonpath='{.data.token}' &> /dev/null; do
+TIMEOUT=60
+ELAPSED=0
+until TOKEN_DATA=$(kubectl get secret "$SECRET_NAME" -n "$NAMESPACE" -o jsonpath='{.data.token}' 2>/dev/null) && [ -n "$TOKEN_DATA" ]; do
+    if [ "$ELAPSED" -ge "$TIMEOUT" ]; then
+        echo "Error: Timed out waiting for secret $SECRET_NAME to be populated" >&2
+        exit 1
+    fi
     sleep 1
+    ELAPSED=$((ELAPSED + 1))
 done
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
# Wait for the secret to be populated with the token
echo "Waiting for secret $SECRET_NAME to be populated..."
until kubectl get secret "$SECRET_NAME" -n "$NAMESPACE" -o jsonpath='{.data.token}' &> /dev/null; do
sleep 1
done
# Wait for the secret to be populated with the token
echo "Waiting for secret $SECRET_NAME to be populated..."
TIMEOUT=60
ELAPSED=0
until TOKEN_DATA=$(kubectl get secret "$SECRET_NAME" -n "$NAMESPACE" -o jsonpath='{.data.token}' 2>/dev/null) && [ -n "$TOKEN_DATA" ]; do
if [ "$ELAPSED" -ge "$TIMEOUT" ]; then
echo "Error: Timed out waiting for secret $SECRET_NAME to be populated" >&2
exit 1
fi
sleep 1
ELAPSED=$((ELAPSED + 1))
done
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@hacks/generate-ocpci-kubeconfig.sh` around lines 17 - 21, The polling loop
using `kubectl get secret "$SECRET_NAME" -n "$NAMESPACE" -o
jsonpath='{.data.token}'` should verify the token is non-empty and add a
timeout; change the loop to repeatedly fetch the token value and check that the
result is not an empty string (not just that `kubectl` succeeded), track elapsed
time or a retry counter (e.g., TIMEOUT or MAX_RETRIES) and break with a non-zero
exit and clear error message if the token is still empty after the timeout,
otherwise proceed when a non-empty token is returned.

@kpouget
kpouget merged commit 1f7fd0b into openshift-psap:main Apr 7, 2026
4 checks passed
@kpouget
kpouget deleted the manifests branch April 7, 2026 13:02
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.

MVP: Allow FORGE-on-OCPCI to submit new jobs and wait for completion.

2 participants