Skip to content

Conversation

@thomasdarimont
Copy link
Contributor

@thomasdarimont thomasdarimont commented Aug 18, 2025

This ensures that the securityDefensesSettings propagated to the terraform state.

Previously we didn't set the security defenses settings configuration generated by Keycloak. As a consequence
terraform was not aware of the actual security defines configuration and attempted to perform a bigger update than necessary.

Fixes #1257

…loak#1257)

This ensures that the securityDefensesSettings propagated to the terraform state.

Avoid repeated call to setRealmData(..) from resourceKeycloakRealmCreate.

Mark resource_keycloak_realm `security_defenses` property as computed as it is populated with defaults after realm creation.

Fixes keycloak#1257

Signed-off-by: Thomas Darimont <[email protected]>
@thomasdarimont thomasdarimont force-pushed the issue/gh-1257-missing-state-check-for-security-settings branch from e45bb10 to 91a5cc8 Compare August 18, 2025 16:06
Copy link
Contributor Author

@thomasdarimont thomasdarimont left a comment

Choose a reason for hiding this comment

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

Some explanations.

DefaultOptionalClientScopes []string `json:"defaultOptionalClientScopes,omitempty"`

BrowserSecurityHeaders BrowserSecurityHeaders `json:"browserSecurityHeaders"`
BrowserSecurityHeaders *BrowserSecurityHeaders `json:"browserSecurityHeaders,omitempty"`
Copy link
Contributor Author

Choose a reason for hiding this comment

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

omitempty allows us to leverage the BrowserSecurityHeader defaults from Keycloak.

if realm.BruteForceProtected {
securityDefensesSettings["brute_force_detection"] = []interface{}{getBruteForceDetectionSettings(realm)}
}
data.Set("security_defenses", []interface{}{securityDefensesSettings})
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 populates the tfstate with the security defenses defaults configured generated by Keycloak.

}

setRealmData(data, realm, keycloakVersion)
data.SetId(realm.Realm)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The call to setRealmData(...) was not necessary as it is already done by resourceKeycloakRealmRead(..), however we do need to set the realm ID via SetId before.

Copy link
Contributor Author

@thomasdarimont thomasdarimont left a comment

Choose a reason for hiding this comment

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

Some explanations.

@thomasdarimont thomasdarimont marked this pull request as draft August 18, 2025 16:25
…oak default securityDefensesHeaders configuration

Signed-off-by: Thomas Darimont <[email protected]>
@ajoga
Copy link
Contributor

ajoga commented Aug 19, 2025

I think you'll be solving #1019 and #218 too with this, good job!

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.

Empty string attributes are not enforced – cannot reset fields like description to empty

2 participants