Skip to content

re-applying changes from reverted Pull #3684#5118

Closed
sudhirakondi wants to merge 4 commits intoopenconfig:mainfrom
sudhirakondi:pr3684
Closed

re-applying changes from reverted Pull #3684#5118
sudhirakondi wants to merge 4 commits intoopenconfig:mainfrom
sudhirakondi:pr3684

Conversation

@sudhirakondi
Copy link
Copy Markdown
Contributor

Changes merged via PR #3684 were reverted by #5114. As I understood from Amritha, there were some issues faced due to the changes in the PR 3684. Raising this PR as recommended, with same changes as in PR 3684.

@sudhirakondi sudhirakondi requested review from a team as code owners February 21, 2026 12:46
@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @sudhirakondi, 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 focuses on re-establishing robust testing for gNSI client certificate functionality. It introduces a new, detailed test suite that covers various scenarios for client certificate validation and rotation across multiple gRPC services. The changes also include refinements to test data generation and the introduction of a dedicated utility package to streamline test setup and verification processes, ensuring the stability and correctness of certificate handling.

Highlights

  • Re-application of Reverted Changes: This pull request reintroduces the changes from a previously reverted PR (certz1.1/1.2 #3684), which was rolled back due to identified issues. The current PR aims to re-integrate these changes as recommended.
  • New gNSI Client Certificate Test Suite: A comprehensive test suite (client_certificates_test.go) has been added to validate gNSI client certificate loading, authentication, and rotation across various gRPC services (gNMI, gNOI, gNSI, gRIBI, P4RT).
  • Test Data Management Refinement: The scripts for generating and cleaning up test data (mk_cas.sh, cleanup.sh) have been updated to exclude the 20000 CA configuration, likely to optimize test runtime or resource usage.
  • Centralized Test Setup Utilities: A new internal package (setup_service.go) was introduced to encapsulate common helper functions for setting up and verifying test environments, promoting code reusability and maintainability.
  • Dependency Update: The go.mod and go.sum files were updated to include a new dependency, go.mozilla.org/pkcs7, which is used for handling PKCS#7 trust bundles in the new test infrastructure.
Changelog
  • feature/gnsi/certz/test_data/README.md
    • Updated TODO comments to reflect changes in CA trust bundle configurations.
  • feature/gnsi/certz/test_data/cleanup.sh
    • Modified the script to exclude the 'ca-20000' directory from cleanup operations.
  • feature/gnsi/certz/test_data/mk_cas.sh
    • Updated the script to remove the '20000' CA configuration from the DIRS array, reducing the number of generated CA sets.
  • feature/gnsi/certz/tests/client_certificates/README.md
    • Updated the title from 'Certz-1' to 'CERTZ-1'.
    • Removed an empty line after the SPIFFEE ID format block.
    • Removed multiple empty lines before the 'Baseline Setup' section.
    • Added TODO comments regarding the 20000 CA configuration and its impact on runtime.
    • Updated the permutations of CA trust_bundle configurations to exclude 20000.
    • Removed an empty line after the client connections validation step.
    • Removed an empty line after the connection torn down validation step.
    • Added certz.v1.Certz.AddProfile and certz.v1.Certz.Rotate to the gNSI RPC coverage list.
  • feature/gnsi/certz/tests/client_certificates/client_certificates_test.go
    • Added a new Go test file to validate gNSI client certificates across various gRPC services, including positive and negative test cases for certificate rotation and authentication.
  • feature/gnsi/certz/tests/client_certificates/metadata.textproto
    • Updated the plan_id from 'Certz-1' to 'CERTZ-1'.
  • feature/gnsi/certz/tests/internal/setup_service/setup_service.go
    • Added a new Go file containing utility functions for gNSI client certificate test setup, including credential handling, certificate chain creation, trust bundle loading, certificate rotation logic, and service verification for gNSI, gNOI, gNMI, gRIBI, and P4RT.
  • feature/security/gnsi/certz/tests/client_certificates/README.md
    • Added a new README file detailing the gNSI Client Certificate Tests, including summary, baseline setup, positive and negative test cases, and OpenConfig path/RPC coverage.
  • feature/security/gnsi/certz/tests/client_certificates/client_certificates_test.go
    • Added a new Go test file for gNSI client certificate validation, including user creation, test data generation, SSL profile management, and comprehensive test cases for certificate rotation and service validation.
  • feature/security/gnsi/certz/tests/client_certificates/metadata.textproto
    • Added a new metadata file for the gNSI client certificate tests, specifying UUID, plan ID, description, and testbed.
  • feature/security/gnsi/certz/tests/internal/setup_service/setup_service.go
    • Added a new Go file containing helper functions for gNSI client certificate test setup, including credential management, certificate chain and entity creation, test data generation/cleanup, server certificate decoding, and verification of gNSI, gNOI, gNMI, gRIBI, and P4RT services.
  • go.mod
    • Added a new dependency: go.mozilla.org/pkcs7 v0.9.0.
  • go.sum
    • Added checksums for the new go.mozilla.org/pkcs7 dependency.
Activity
  • This pull request is a re-application of changes from a previously merged PR (certz1.1/1.2 #3684) that was subsequently reverted by PR Revert "certz1.1/1.2" #5114 due to reported issues. The author is re-submitting these changes as recommended, indicating a prior cycle of review, integration, and rollback.
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
Copy Markdown
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 introduces a new test for gNSI client certificates and updates related test data generation scripts. The changes look good overall, but there are several areas for improvement.

Notably, the PR appears to include duplicated test files under both feature/gnsi/certz and feature/security/gnsi/certz. The files under feature/security seem to be an older version and contain unresolved merge conflicts, which is a critical issue. Please clarify if this is intentional, and if not, remove the duplicated files.

In the test implementation, there are some issues with global variables, including one that causes stale timestamps in logs and another that should be a local variable. The logic for waiting for a gRPC response is flawed and can lead to test hangs, but the suggested fix aligns with best practices for handling critical test failures. Additionally, several verification functions have an unused mismatch parameter, indicating incomplete logic for negative test cases. I've also pointed out a violation of the style guide regarding the use of time.Sleep.

Comment on lines +255 to +285
//RotateRequest receive channel to receive the next response message.
ch := make(chan struct{}, 1)
rotateResponse := &certzpb.RotateCertificateResponse{}
wg.Add(1)
go func() {
defer wg.Done()
rotateResponse, err = rotateRequestClient.Recv()
if err != nil {
t.Errorf("Error fetching rotate certificate response: %v", err)
return
}
close(ch)
}()
for i := range retries {
wg.Add(1)
go func(i int) {
defer wg.Done()
for {
select {
case <-ch:
//Exiting receive channel.
return
default:
//Did not receive response after sending rotate request.Sleeping 10s to retry.
time.Sleep(10 * time.Second)
}
}
}(i)
}
wg.Wait()
t.Logf("Received Rotate certificate response: %v", rotateResponse)
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.

critical

The current implementation for waiting for the Recv() response is overly complex, inefficient, and contains a bug. It spawns multiple goroutines that spin-wait, which is not a standard or clear way to implement a timeout. Furthermore, if Recv() returns an error, the channel ch is never closed, causing the waiting goroutines to hang indefinitely. A much simpler and more idiomatic Go approach is to use a select statement with a time.After channel for the timeout.

	// Wait for the rotate response with a timeout.
	respCh := make(chan *certzpb.RotateCertificateResponse)
	errCh := make(chan error)
	go func() {
		resp, err := rotateRequestClient.Recv()
		if err != nil {
			errCh <- err
			return
		}
		respCh <- resp
	}()

	var rotateResponse *certzpb.RotateCertificateResponse
	select {
	case rotateResponse = <-respCh:
		t.Logf("Received Rotate certificate response: %v", rotateResponse)
	case err := <-errCh:
		t.Fatalf("Error fetching rotate certificate response: %v", err)
	case <-time.After(time.Duration(retries) * 10 * time.Second): // e.g. 12 * 10s = 2 minutes timeout
		t.Fatalf("Timed out waiting for rotate certificate response")
	}
References
  1. When monitoring critical processes in a test, use t.Fatalf if a process is not found, as its absence should be considered a fatal test failure.

Comment thread feature/security/gnsi/certz/tests/client_certificates/README.md Outdated
Comment thread feature/gnsi/certz/tests/internal/setup_service/setup_service.go
var (
serverAddr string
creds DUTCredentialer //an interface for getting credentials from a DUT binding
testProfile string = "newprofile" //sslProfileId name
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.

medium

This variable is used as a constant. It should be declared as a const to follow Go conventions and prevent accidental changes.

const testProfile = "newprofile"
References
  1. Per Effective Go, compile-time constants should be declared using the const keyword. (link)

prevClientCertFile string = ""
prevClientKeyFile string = ""
prevTrustBundleFile string = ""
logTime string = time.Now().String() //Timestamp
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.

medium

The logTime global variable is initialized only once when the package is loaded. This means all log messages throughout the test execution will have the same stale timestamp. It is recommended to remove this variable and rely on the test runner's built-in timestamping. If custom timestamping is required, time.Now() should be called within each logging statement to get a fresh timestamp.

servers []string
retries int = 12
wg sync.WaitGroup
success bool
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.

medium

The global variable success is only used within the CertzRotate function. It should be declared as a local variable inside that function (e.g., if success := VerifyGnsi(...); !success) to improve code clarity and avoid potential side effects from global state.

}
batch.Set(t, dut.GNMIOpts().WithClient(gnmiClient))
t.Logf("gNMI config is replaced with new ssl profile %s successfully.", profileID)
time.Sleep(30 * time.Second) //waiting 30s for gnmi config propagation//
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.

medium

The style guide recommends avoiding time.Sleep and using gnmi.Watch with .Await to wait for conditions to be met. This time.Sleep should be replaced with a watch on the gNMI config to confirm propagation.

References
  1. The repository style guide specifies to avoid time.Sleep and instead use gnmi.Watch with .Await for waiting on conditions. (link)

// TestdataMakeCleanup function to create/cleanup test data for use in TLS tests.
// This function executes the certificate generate/cleanup script "mk_cas.sh" and "cleanup.sh"
// located in the specified dir at the start and end of the tests repectively.
func TestdataMakeCleanup(t *testing.T, dirPath string, timeout time.Duration, args string) error {
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.

medium

The function name TestdataMakeCleanup is a bit misleading as it's a generic function to run shell scripts, used for both setup (mk_cas.sh) and cleanup (cleanup.sh). A more descriptive name like RunScriptInDir would better reflect its purpose.

func RunScriptInDir(t *testing.T, dirPath string, timeout time.Duration, script string) error {

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