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

Fix #857 Add provider_id config to keycloak_realm_keystore_rsa resource: Enable creating encryption keys #858

Merged
merged 4 commits into from
Jan 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion docs/resources/realm_keystore_rsa.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ resource "keycloak_realm_keystore_rsa" "keystore_rsa" {
priority = 100
algorithm = "RS256"
keystore_size = 2048
provider_id = "rsa"
}
```

Expand All @@ -40,8 +41,9 @@ resource "keycloak_realm_keystore_rsa" "keystore_rsa" {
- `enabled` - (Optional) When `false`, key is not accessible in this realm. Defaults to `true`.
- `active` - (Optional) When `false`, key in not used for signing. Defaults to `true`.
- `priority` - (Optional) Priority for the provider. Defaults to `0`
- `algorithm` - (Optional) Intended algorithm for the key. Defaults to `RS256`
- `algorithm` - (Optional) Intended algorithm for the key. Defaults to `RS256`. Use `RSA-OAEP` for encryption keys
- `keystore_size` - (Optional) Size for the generated keys. Defaults to `2048`.
- `provider_id` - (Optional) Use `rsa` for signing keys, `rsa-enc` for encryption keys

## Import

Expand Down
4 changes: 3 additions & 1 deletion keycloak/realm_keystore_rsa.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ type RealmKeystoreRsa struct {

PrivateKey string
Certificate string
ProviderId string
}

func convertFromRealmKeystoreRsaToComponent(realmKey *RealmKeystoreRsa) *component {
Expand Down Expand Up @@ -46,7 +47,7 @@ func convertFromRealmKeystoreRsaToComponent(realmKey *RealmKeystoreRsa) *compone
Id: realmKey.Id,
Name: realmKey.Name,
ParentId: realmKey.RealmId,
ProviderId: "rsa",
ProviderId: realmKey.ProviderId,
ProviderType: "org.keycloak.keys.KeyProvider",
Config: componentConfig,
}
Expand Down Expand Up @@ -82,6 +83,7 @@ func convertFromComponentToRealmKeystoreRsa(component *component, realmId string
Algorithm: component.getConfig("algorithm"),
PrivateKey: component.getConfig("privateKey"),
Certificate: component.getConfig("certificate"),
ProviderId: component.ProviderId,
}

return realmKey, nil
Expand Down
11 changes: 10 additions & 1 deletion provider/resource_keycloak_realm_keystore_rsa.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
)

var (
keycloakRealmKeystoreRsaAlgorithm = []string{"RS256", "RS384", "RS512", "PS256", "PS384", "PS512"}
keycloakRealmKeystoreRsaAlgorithm = []string{"RS256", "RS384", "RS512", "PS256", "PS384", "PS512", "RSA-OAEP"}
)

func resourceKeycloakRealmKeystoreRsa() *schema.Resource {
Expand Down Expand Up @@ -67,6 +67,13 @@ func resourceKeycloakRealmKeystoreRsa() *schema.Resource {
Required: true,
Description: "X509 Certificate encoded in PEM format",
},
"provider_id": {
Type: schema.TypeString,
Optional: true,
Default: "rsa",
Description: "RSA key provider id",
ForceNew: true,
},
},
}
}
Expand All @@ -83,6 +90,7 @@ func getRealmKeystoreRsaFromData(data *schema.ResourceData) *keycloak.RealmKeyst
Algorithm: data.Get("algorithm").(string),
PrivateKey: data.Get("private_key").(string),
Certificate: data.Get("certificate").(string),
ProviderId: data.Get("provider_id").(string),
}

return mapper
Expand All @@ -98,6 +106,7 @@ func setRealmKeystoreRsaData(data *schema.ResourceData, realmKey *keycloak.Realm
data.Set("enabled", realmKey.Enabled)
data.Set("priority", realmKey.Priority)
data.Set("algorithm", realmKey.Algorithm)
data.Set("provider_id", realmKey.ProviderId)
if realmKey.PrivateKey != "**********" {
data.Set("private_key", realmKey.PrivateKey)
data.Set("certificate", realmKey.Certificate)
Expand Down