Skip to content
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

Add update logic #7

Merged
merged 10 commits into from
Nov 28, 2022
Merged

Add update logic #7

merged 10 commits into from
Nov 28, 2022

Conversation

anvddriesch
Copy link
Contributor

@anvddriesch anvddriesch commented Nov 17, 2022

Towards giantswarm/roadmap#1629

This adds update logic for identity providers, namely azure.
Updates include changes to the connector configuration such as claims, permissions and redirect URI as well as secret rotation.

@anvddriesch anvddriesch self-assigned this Nov 21, 2022
@anvddriesch anvddriesch changed the title WIP: add update logic Add update logic Nov 22, 2022
}
{
// Get existing connectors from the dex config secret
oldConnectors, err := getConnectorsFromSecret(secret)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We save the connectors that were previously configured in a map so that we can later compare what was changed.

@@ -196,6 +207,33 @@ func (s *Service) DeleteProviderApps(appName string, ctx context.Context) error
return nil
}

func (s *Service) secretNeedsUpdate(oldConnectors map[string]dex.Connector, newConnectors map[string]dex.Connector) bool {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Here we compare old connector configuration to new connector configuration. (see comments)

"github.com/microsoftgraph/msgraph-sdk-go/models"
"gopkg.in/yaml.v2"
)

type Azure struct {
Name string
Client *msgraphsdk.GraphServiceClient
Log *logr.Logger
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We add a logger here so that changes on the azure idp which are not reflected in the connector can still be seen in the logs

@@ -128,6 +128,110 @@ func (a *Azure) CreateApp(config provider.AppConfig, ctx context.Context) (dex.C
}, nil
}

func (a *Azure) createOrUpdateApplication(config provider.AppConfig, ctx context.Context) (string, error) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Create and update of the azure app excluding the secret happens here

return *id, nil
}

func (a *Azure) createOrUpdateSecret(id string, config provider.AppConfig, ctx context.Context, oldSecret string) (string, string, error) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Secret creation and rotation happens here

return clientId, clientSecret, nil
}

func secretExpired(secret models.PasswordCredentialable) bool {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this checks whether a secret is expired

app := models.NewApplication()
app.SetRequiredResourceAccess(parentApp.GetRequiredResourceAccess())
return app
func computeAppUpdatePatch(config provider.AppConfig, app models.Applicationable, parentApp models.Applicationable) (bool, models.Applicationable) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This function computes a patch for the app by comparing desired and current state for each property

@@ -43,3 +46,23 @@ func GetDexSecretConfig(namespace string) v1alpha1.AppExtraConfig {
Namespace: namespace,
Priority: 25}
}

func getConnectorsFromSecret(secret *corev1.Secret) (map[string]dex.Connector, error) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This function creates a map out of the connector secret so that connectors can be compared more easily

)

const (
SecretValidityMonths = 6
SecretValidityMonths = 3
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Since we have automatic rotation now we changed this here to 3 months

@anvddriesch anvddriesch marked this pull request as ready for review November 22, 2022 13:43
@anvddriesch anvddriesch requested a review from a team November 22, 2022 13:43
@anvddriesch anvddriesch merged commit 400d09a into main Nov 28, 2022
@anvddriesch anvddriesch deleted the updatelogic branch November 28, 2022 09:42
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