Skip to content

add ServiceAccount to openshift template#118

Merged
openshift-merge-bot[bot] merged 1 commit intorh-ecosystem-edge:mainfrom
maorfr:sa
Aug 13, 2025
Merged

add ServiceAccount to openshift template#118
openshift-merge-bot[bot] merged 1 commit intorh-ecosystem-edge:mainfrom
maorfr:sa

Conversation

@maorfr
Copy link
Collaborator

@maorfr maorfr commented Aug 12, 2025

part of https://issues.redhat.com/browse/MGMT-21020

adding a ServiceAccount to avoid using default and also using a pull secret for auth.

Summary by CodeRabbit

  • Chores
    • Introduced a dedicated service account with an image pull secret to enable pulling container images from the private registry.
    • Updated the deployment to use the new service account, improving reliability of image pulls and reducing deployment failures.
    • Enhanced operational security by scoping registry access through the service account.
    • No user-facing UI changes; deployment behavior is more stable and consistent across environments.

@openshift-ci openshift-ci bot requested review from keitwb and omertuc August 12, 2025 06:33
@openshift-ci
Copy link

openshift-ci bot commented Aug 12, 2025

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: maorfr

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

@coderabbitai
Copy link

coderabbitai bot commented Aug 12, 2025

Walkthrough

Introduces a ServiceAccount named assisted-chat with imagePullSecrets for quay.io and updates the assisted-chat Deployment to use this ServiceAccount via serviceAccountName.

Changes

Cohort / File(s) Summary
Kubernetes manifest updates
template.yaml
Added ServiceAccount assisted-chat with label app: assisted-chat and imagePullSecrets: quay.io; updated Deployment to set spec.serviceAccountName: assisted-chat.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Possibly related PRs

  • adding openshift template #12 — Also modifies assisted-chat Deployment in template.yaml; this PR complements it by adding a ServiceAccount and wiring serviceAccountName.

Suggested reviewers

  • jhernand
✨ Finishing Touches
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

‼️ IMPORTANT
Auto-reply has been disabled for this repository in the CodeRabbit settings. The CodeRabbit bot will not respond to your replies unless it is explicitly tagged.

  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

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

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@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: 1

🧹 Nitpick comments (1)
template.yaml (1)

393-393: Good: Deployment now uses the dedicated ServiceAccount; consider disabling token automount at Pod level

serviceAccountName is correctly set. For additional hardening (if the app doesn’t need in-cluster API), disable token automount at the Pod level as well.

Suggested diff:

       spec:
-        serviceAccountName: assisted-chat
+        serviceAccountName: assisted-chat
+        automountServiceAccountToken: false

Please confirm the containers don’t need Kubernetes API access; otherwise, skip this change.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 0038bbb and 92a5ce8.

📒 Files selected for processing (1)
  • template.yaml (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Red Hat Konflux / assisted-chat-saas-main-on-pull-request

Comment on lines +368 to +376
- apiVersion: v1
kind: ServiceAccount
metadata:
name: assisted-chat
labels:
app: assisted-chat
imagePullSecrets:
- name: quay.io

Copy link

Choose a reason for hiding this comment

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

💡 Verification agent

🧩 Analysis chain

Hardcoded imagePullSecret name will break in most clusters; parameterize and disable token automount

Referencing a Secret named "quay.io" is unlikely to work across environments. The Secret must pre-exist in the target namespace and is typically named by teams (e.g., quay-pull-secret). Also, for least-privilege, avoid mounting service account tokens when not needed.

  • Parameterize the pull secret name so the template remains portable.
  • Add automountServiceAccountToken: false to reduce token exposure.

Apply this diff within the ServiceAccount:

   kind: ServiceAccount
   metadata:
     name: assisted-chat
     labels:
       app: assisted-chat
-  imagePullSecrets:
-  - name: quay.io
+  automountServiceAccountToken: false
+  imagePullSecrets:
+  - name: ${IMAGE_PULL_SECRET_NAME}

Add this parameter to the template’s parameters section (outside this hunk):

- name: IMAGE_PULL_SECRET_NAME
  required: true
  description: "Name of an existing Secret (type kubernetes.io/dockerconfigjson) with quay.io credentials"

Verification:

  • Ensure the Secret ${IMAGE_PULL_SECRET_NAME} exists in the same namespace before applying the template.
  • Confirm it is of type kubernetes.io/dockerconfigjson.

If you want, I can add a Secret object to this template (disabled by default) or provide docs on how to create one with ‘oc create secret docker-registry …’.


I’ll verify the presence of parameters and the hardcoded pull secret reference in template.yaml. Once confirmed, I’ll rewrite the comment accordingly.


🏁 Script executed:

#!/bin/bash
# Locate template.yaml
file=$(fd template.yaml | head -n1)
echo "Using file: $file"

# Show parameters section (first 50 lines)
echo; echo "=== parameters section ==="
grep -R "parameters:" -n "$file" | head -n5
sed -n '1,50p' "$file"

# Show lines 350–400 around the ServiceAccount
echo; echo "=== lines 350–400 ==="
sed -n '350,400p' "$file"

# Confirm any existing IMAGE_PULL_SECRET_NAME parameter
grep -R "IMAGE_PULL_SECRET_NAME" -n "$file"

# Confirm hardcoded quay.io reference
grep -R "quay.io" -n "$file"

Length of output: 3642


Parameterize Image Pull Secret and Disable Service Account Token Automount

Hardcoding the imagePullSecret “quay.io” will fail in clusters where the pull‐secret is named differently or doesn’t exist. To keep this template portable and adhere to least‐privilege principles, please:

• Introduce a required parameter for the pull‐secret name.
• Set automountServiceAccountToken to false on the ServiceAccount.

Suggested changes in template.yaml:

--- a/template.yaml
+++ b/template.yaml
@@ parameters:
 - name: GEMINI_API_SECRET_NAME
   value: "assisted-chat-gemini-secret"
   description: "Name of the Kubernetes secret containing the Gemini API key"
+- name: IMAGE_PULL_SECRET_NAME
+  required: true
+  description: "Name of an existing Secret (type kubernetes.io/dockerconfigjson) for pulling images from quay.io"
 
@@ kind: ServiceAccount
   metadata:
     name: assisted-chat
     labels:
       app: assisted-chat
-  imagePullSecrets:
-  - name: quay.io
+  automountServiceAccountToken: false
+  imagePullSecrets:
+  - name: ${IMAGE_PULL_SECRET_NAME}

Before instantiating the template, ensure the named secret exists in the target namespace and is of type kubernetes.io/dockerconfigjson.

📝 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
- apiVersion: v1
kind: ServiceAccount
metadata:
name: assisted-chat
labels:
app: assisted-chat
imagePullSecrets:
- name: quay.io
- apiVersion: v1
kind: ServiceAccount
metadata:
name: assisted-chat
labels:
app: assisted-chat
automountServiceAccountToken: false
imagePullSecrets:
- name: ${IMAGE_PULL_SECRET_NAME}
🤖 Prompt for AI Agents
In template.yaml around lines 368 to 376, the ServiceAccount currently hardcodes
imagePullSecrets: - name: quay.io and does not disable token automount; change
this by adding a required template parameter (e.g., ImagePullSecretName) and
replace the hardcoded name with the parameter reference for the imagePullSecrets
entry, then add automountServiceAccountToken: false under the ServiceAccount
spec to disable token automount; also ensure the parameter is marked required in
the template parameters section so callers must provide the pull-secret name.

Copy link
Collaborator

@eranco74 eranco74 left a comment

Choose a reason for hiding this comment

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

/lgtm
/cc @andrej1991 though I don't think it should have an effect on the CI job

@openshift-ci openshift-ci bot added the lgtm label Aug 13, 2025
@openshift-merge-bot openshift-merge-bot bot merged commit cebff1a into rh-ecosystem-edge:main Aug 13, 2025
5 checks passed
@coderabbitai coderabbitai bot mentioned this pull request Aug 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants