Skip to content

Conversation

@MartinTrojans
Copy link
Contributor

@MartinTrojans MartinTrojans commented Nov 18, 2025

Description

Contribution Checklist:

  • The pull request does not introduce any breaking changes
  • I have read the contribution guidelines.
  • Create an issue and link to the pull request.

Attach Screenshots (Optional)

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @MartinTrojans, 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 enhances the Athenz Service Identity Agent (SIA) for Google Cloud Platform (GCP) by integrating Kubernetes-native mechanisms for service identity attestation. It introduces the ability for applications deployed on Google Kubernetes Engine (GKE) to declare their default service identity through annotations on their Kubernetes service accounts. This provides a more flexible and Kubernetes-idiomatic way to manage service identities, complementing the existing metadata server-based approach.

Highlights

  • GKE Service Identity Support: The Athenz SIA GCP attestation library now supports retrieving default service identities from Kubernetes service account annotations when running in a GKE environment.
  • Kubernetes Integration: New functions (isRunningInGKE, getServiceAccountAnnotation, getCurrentServiceAccountName) and k8s.io/client-go dependencies are introduced to interact with the Kubernetes API to fetch service account details.
  • Fallback Mechanism: The system gracefully falls back to using the GCP metadata server for service identity if not running in GKE or if the required Kubernetes annotation (athenz.io/default-service-identity) is not found on the service account.
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-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 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 counter productive. You can react with 👍 and 👎 on @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.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

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.

Copy link
Contributor

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

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 adds support for GKE to the Athenz SIA GCP attestation library, allowing pods to specify their default service identity via Kubernetes service account annotations. The changes are well-structured and include new functions for interacting with the Kubernetes API to fetch annotations. The tests cover the new functionality, although one test name is a bit misleading. My review includes suggestions for improving robustness, adhering to best practices for context handling, and ensuring proper error handling. Overall, this is a good addition to the library.

defaultIdentity := ""
if isRunningInGKE() {
// Get the default identity from the service account annotation
defaultIdentity, _ = getServiceAccountAnnotation("athenz.io/default-service-identity")
Copy link
Contributor

Choose a reason for hiding this comment

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

high

The error returned by getServiceAccountAnnotation is ignored. If the function fails (e.g., due to missing RBAC permissions), the error is suppressed, and defaultIdentity will be an empty string. This can lead to silent failures and unexpected behavior. The error should be logged to provide visibility into potential issues.

                var err error
                defaultIdentity, err = getServiceAccountAnnotation("athenz.io/default-service-identity")
                if err != nil {
                        log.Printf("unable to get default service identity from pod annotation: %v", err)
                }

return "", fmt.Errorf("failed to get current service account name: %v", err)
}

serviceAccount, err := clientset.CoreV1().ServiceAccounts(namespace).Get(context.Background(), serviceAccountName, metav1.GetOptions{})
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

The Kubernetes API call uses context.Background(). It's better to accept a context.Context as an argument in getServiceAccountAnnotation and pass it down to the API calls. This allows callers to manage timeouts and cancellations. This would likely require propagating the context up to the New function. A similar issue exists in getCurrentServiceAccountName on line 94.


// getCurrentServiceAccountName gets the service account name of the current pod
func getCurrentServiceAccountName(clientset *kubernetes.Clientset, namespace string) (string, error) {
podName := os.Getenv("HOSTNAME")
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

Using os.Getenv("HOSTNAME") to get the pod name is not always reliable. If a pod's spec.hostname is set, the HOSTNAME environment variable will be set to that value, which is not the pod's name. A more robust approach is to use the Downward API to expose the pod name as an environment variable. For example, you can add this to your pod spec:

env:
- name: POD_NAME
  valueFrom:
    fieldRef:
      fieldPath: metadata.name

Then in your code, you can use os.Getenv("POD_NAME"). This ensures you always get the correct pod name.

Comment on lines 403 to 404
// TestNewWithGKEFallback tests that when running in GKE but annotation fails,
// it falls back to metadata
func TestNewWithGKEFallback(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

The test name TestNewWithGKEFallback and its comment suggest that it tests a fallback from GKE annotation to instance metadata. However, the implementation in attestation.go does not have this fallback logic; it's a strict if/else. Also, as noted in the test, it actually only tests the non-GKE path. This is confusing. Please consider renaming the test to reflect what it actually tests (e.g., TestNewWithMetadata) and clarify if a fallback from GKE annotation to metadata is desired. If so, the implementation in New() needs to be updated.

@havetisyan havetisyan merged commit 8c360ec into AthenZ:master Nov 24, 2025
3 checks passed
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.

2 participants