-
Notifications
You must be signed in to change notification settings - Fork 281
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
Fixing bug where variable group fails to map new variable after service endpoint secret rotates #826
Conversation
@rdalbuquerque Since this is an AzureRM service connection secret rotate issue, suggest use API(https://learn.microsoft.com/en-us/rest/api/azure/devops/serviceendpoint/endpointproxy/execute-service-endpoint-request?tabs=HTTP) to do the validation for service connection. Currently all service connections not do the validation by default which means all secrets can be dummy values. Add the retry logic in VG only resolve part of the issue as other resource may also face the same issue. |
@xuzhang3 Ok, so I played around a few scenarios to make this validation possible and more generic: func validateServiceEndpointConnection(clients *client.AggregatedClient, endpoint *serviceendpoint.ServiceEndpoint) error {
reqArgs := serviceendpoint.ExecuteServiceEndpointRequestArgs{
ServiceEndpointRequest: &serviceendpoint.ServiceEndpointRequest{
DataSourceDetails: &serviceendpoint.DataSourceDetails{
DataSourceName: converter.String("TestConnection"),
},
ResultTransformationDetails: &serviceendpoint.ResultTransformationDetails{},
},
Project: converter.String((*endpoint.ServiceEndpointProjectReferences)[0].ProjectReference.Id.String()),
EndpointId: converter.String(endpoint.Id.String()),
}
maxRetries := 15 // should probably be an input
retryInverval := 2 // should probably be an input
var reqResult *serviceendpoint.ServiceEndpointRequestResult
var err error
log.Printf(fmt.Sprintf(":: serviceendpoint/commons.go :: %s :: Initiating validation", *endpoint.Name))
for i := 0; i < maxRetries; i++ {
if reqResult, err = clients.ServiceEndpointClient.ExecuteServiceEndpointRequest(clients.Ctx, reqArgs); err != nil {
log.Printf(fmt.Sprintf(":: serviceendpoint/commons.go :: %s :: error during endpoint validation request", *endpoint.Name))
return err
} else if strings.EqualFold(*reqResult.StatusCode, "ok") {
log.Printf(fmt.Sprintf(":: serviceendpoint/commons.go :: %s :: successfully validated connection", *endpoint.Name))
return nil
}
log.Printf(fmt.Sprintf(":: serviceendpoint/commons.go :: %s :: validation failed, retrying...", *endpoint.Name))
time.Sleep(time.Duration(retryInverval) * time.Second)
}
return fmt.Errorf("Error validating connection: (type: %s, name: %s, code: %s, message: %s)", *endpoint.Type, *endpoint.Name, *reqResult.StatusCode, *reqResult.ErrorMessage)
}
Hopefully this can be solved. Thanks in advance! |
|
@xuzhang3 So for this first attempt I did the following:
type serviceEndpointWithValidation struct {
endpoint *serviceendpoint.ServiceEndpoint
validate bool
}
type flatFunc func(d *schema.ResourceData, serviceEndpoint *serviceEndpointWithValidation, projectID *uuid.UUID)
type expandFunc func(d *schema.ResourceData) (*serviceEndpointWithValidation, *uuid.UUID, error)
One issue I couldn't figure out the best way to handle is that even if the update fails and, on the update, I'm changing the validate, ok := d.Get("validate").(bool)
if !ok {
validate = false
}
flatFunc(d, &serviceEndpointWithValidation{endpoint: serviceEndpoint, validate: validate}, &projectID) Looking forward to you feedback :) |
@rdalbuquerque currently all the service connections share the same create/update/read/delete function which is a limitation to all the service connection resources, some service connections have specifical configurations which is only available to itself. We are considering refactoring the service connection resources, every resource has its own create/update/read/delete functions but share the common functions. Each resource can customize its own configuration without affecting other resources. |
@xuzhang3 I see, so we wait the refactor before moving forward with this PR? If there is anything I can do to help refactoring or any other way we can implement this validation on azurerm service endpoint that would not need the refactor, please let me know! |
@rdalbuquerque yes, wait before refactoring. More work is required if this PR is merged. |
@rdalbuquerque #863 will decouple the generic functions, you can add the validation to |
@rdalbuquerque #863 has been merged, you can add the validation to |
All Submissions:
What about the current behavior has changed?
Adding a key vault expansion retry logic in case there is an update to azurerm service endpoint secret.
Issue Number: #825
Also fixing error messages typos
Issue Number: #303
Does this introduce a change to
go.mod
,go.sum
orvendor/
?Does this introduce a breaking change?
Any relevant logs, error output, etc?
(If it’s long, please paste to https://ghostbin.com/ and insert the link here.)
Other information
The tradeoff is that if the secret is in fact wrong it will take 30 seconds to return an error