-
Notifications
You must be signed in to change notification settings - Fork 39
Remote agent refactor cert provider new #810
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: remote-agent
Are you sure you want to change the base?
Remote agent refactor cert provider new #810
Conversation
| 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") |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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": { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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": { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same as above
There was a problem hiding this comment.
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{} |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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( |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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++ { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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"?
remote-agent/bootstrap/bootstrap.ps1
Outdated
| $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") { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
f25212a to
fa66dd4
Compare
f8f6fcb to
3642797
Compare
| 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, |
There was a problem hiding this comment.
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"` |
There was a problem hiding this comment.
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" |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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
No description provided.