Skip to content

Conversation

@yanjiaxin534
Copy link
Contributor

No description provided.

sLog.InfofCtx(ctx, "V (Solution): handleWorkingCertManagement for remote target: %s, remove: %t", deployment.RemoteTargetName, remove)

if c.SolutionManager.GetCertProvider() == nil {
return fmt.Errorf("cert provider is not available")
Copy link
Contributor

Choose a reason for hiding this comment

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

we don't usually check manager's provider before we invoke the manager in vendor.
The check should be in the manager side.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fix it now,thanks

})
}
// Check if targets manager is available for cert provider access
if c.TargetsManager == nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

we don't usually check manager here. We should make sure in the init method.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I fix it now, thanks

"inCluster": true
}
},
"working-cert": {
Copy link
Contributor

Choose a reason for hiding this comment

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

we can name it as cm-cert or k8s-cert

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I fix it now, thanks

"type": "providers.secret.mock",
"config": {}
},
"working-cert": {
Copy link
Contributor

Choose a reason for hiding this comment

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

same as above

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fix it now, thanks

SummaryManager
TargetProviders map[string]tgt.ITargetProvider
CertProvider certProvider.ICertProvider
certProviderConfig map[string]interface{}
Copy link
Contributor

Choose a reason for hiding this comment

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

why you need to keep certProviderConfig here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks, I fix it now.


// Initialize cert provider using unified approach
certProviderInstance, err := managers.GetCertProvider(config, providers)
if err == nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

why we have special case for cert provider initialization?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't need special case, fix it now.

}

// GetCertProvider returns the cert provider instance for certificate management operations
func (s *SolutionManager) GetCertProvider() certProvider.ICertProvider {
Copy link
Contributor

Choose a reason for hiding this comment

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

where did you use this function?


// SafeCreateWorkingCert creates a working certificate with validation checks
// It validates that the certificate doesn't exist before creation and verifies creation success after
func (s *SolutionManager) SafeCreateWorkingCert(ctx context.Context, certID string, request certProvider.CertRequest) error {
Copy link
Contributor

Choose a reason for hiding this comment

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

why we name it as SafeXXX?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fix it now


// SafeDeleteWorkingCert deletes a working certificate with validation checks
// It validates that the certificate exists before deletion and verifies deletion success after
func (s *SolutionManager) SafeDeleteWorkingCert(ctx context.Context, certID string, namespace string) error {
Copy link
Contributor

Choose a reason for hiding this comment

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

why we name it as SafeXXX?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fix it now

}

// Create the certificate
_, err := p.DynamicClient.Resource(certificateGVR).Namespace(req.Namespace).Create(
Copy link
Contributor

Choose a reason for hiding this comment

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

do we need to check the cert object ready status?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Or I think the target create is not successfully.

// Retry logic: retry up to 10 times, 2 seconds interval
var certificate *unstructured.Unstructured
var err error
for i := 0; i < 10; i++ {
Copy link
Contributor

Choose a reason for hiding this comment

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

can you define retryTimes:=10, i < (retryTimes-1) for time.sleep, using magic number is a bad coding style.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fix it now

time.Sleep(2 * time.Second)
}
}
if err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

did you handle not found error? I saw you will use GetCert again for delete case.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, in delete case, when not find after delete, it means sucessfully delete the working cert.

"k8s-cert": {
"type": "providers.cert.k8scert",
"config": {
"inCluster": true,
Copy link
Contributor

Choose a reason for hiding this comment

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

you don't need this option, did you have scenarios other than "inCluster"?

$WebRequestParams.GetEnumerator() | ForEach-Object { Write-Host (" {0}: {1}" -f $_.Key, $_.Value) }
$response = Invoke-WebRequest @WebRequestParams -Verbose
$jsonResponse = $response.Content | ConvertFrom-Json
if ($jsonResponse.public -and $jsonResponse.private -and $jsonResponse.public -ne "null" -and $jsonResponse.private -ne "null") {
Copy link
Contributor

Choose a reason for hiding this comment

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

what does "null" string compare mean? powershell have [string]::IsNullOrEmpty() utility.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is a bug, fix now, thanks

@yanjiaxin534 yanjiaxin534 force-pushed the remote-agent-refactor-cert-provider-new branch 2 times, most recently from f25212a to fa66dd4 Compare September 25, 2025 07:10
@yanjiaxin534 yanjiaxin534 force-pushed the remote-agent-refactor-cert-provider-new branch from f8f6fcb to 3642797 Compare September 28, 2025 12:39
func (s *SolutionManager) createCertRequest(targetName string, namespace string) certProvider.CertRequest {
// Create request with required fields - provider will use its configured defaults for Duration and RenewBefore only
return certProvider.CertRequest{
TargetName: targetName,
Copy link
Contributor

@iwangjintian iwangjintian Sep 29, 2025

Choose a reason for hiding this comment

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

It should be cert name rather than targetname.
The cert request does not only work for remote agent cert scenarios

PublicKey string `json:"publicKey"`
PrivateKey string `json:"privateKey"`
ExpiresAt time.Time `json:"expiresAt"`
SerialNumber string `json:"serialNumber"`
Copy link
Contributor

Choose a reason for hiding this comment

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

It's called thumbprint in cert context

}

func (p *K8SCertProvider) ID() string {
return "k8s-cert"
Copy link
Contributor

Choose a reason for hiding this comment

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

what's this for?

return cert.SerialNumber.String(), cert.NotAfter, nil
}

func (p *K8SCertProvider) CreateCert(ctx context.Context, req cert.CertRequest) error {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think CreateCert interface should return the cert

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.

3 participants