Repository navigation
Add the manifests and scripts to create a Kubeconfig for OCPCI - #20
Conversation
📝 WalkthroughWalkthroughAdds RBAC configuration and a kubeconfig generation script to establish a service account ( Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
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: ConfigAlternatively, 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
📒 Files selected for processing (5)
hacks/generate-ocpci-kubeconfig.shmanifests/ocpci-sa/role.yamlmanifests/ocpci-sa/rolebinding.yamlmanifests/ocpci-sa/sa.yamlmanifests/ocpci-sa/secret.yaml
| # 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 |
There was a problem hiding this comment.
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.
| # 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.
Fix: #16
Summary by CodeRabbit