Skip to content

Commit

Permalink
Merge pull request #1222 from adorsys/feat/minimal-configuration
Browse files Browse the repository at this point in the history
feat: getting minimal config from exported json
  • Loading branch information
AssahBismarkabah authored Dec 2, 2024
2 parents 56d9550 + 0883837 commit b6331fc
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 0 deletions.
67 changes: 67 additions & 0 deletions docs/config/minimal-configuration.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
## Getting Minimal Import After Realm Export

This script is designed to clean up a Keycloak realm configuration file (in JSON format) by removing unnecessary fields, including all `id` fields, from the configuration. It is useful for simplifying the export of Keycloak realm data, especially when certain details like IDs are not needed for sharing or backup purposes.

### Features

- **Removes unnecessary default fields** such as `accessTokenLifespan`, `offlineSessionIdleTimeout`, and others that are typically not needed for a reimport.
- **Simplifies the realm configuration** while retaining all necessary properties for further processing or importing into another Keycloak instance.

### Requirements

- **jq**: This script requires `jq`, a command-line JSON processor, to manipulate the JSON data.

You can install `jq` using the following commands:

- On Ubuntu/Debian:
```bash
sudo apt-get install jq
```
- On macOS (with Homebrew):
```bash
brew install jq
```

### Usage

Ensure you have the Keycloak realm configuration file (in JSON format) that you want to clean. The file should be named `realm-config.json` or you can modify the script to use your desired file path.

### Download or Copy the Script

```bash
#!/bin/bash
INPUT_FILE="realm-config.json"
OUTPUT_FILE="keycloak-realm-export-minimal.json"
jq 'del(
.id, .containerId, .accessTokenLifespanForImplicitFlow,
.accessTokenLifespanForWebApps, .accessTokenLifespan, .offlineSessionIdleTimeout,
.accessTokenLifespanInSeconds, .ssoSessionIdleTimeout, .ssoSessionMaxLifespan,
.ssoSessionIdleTimeoutRememberMe, .ssoSessionMaxLifespanRememberMe,
.accessCodeLifespan, .accessCodeLifespanLogin, .accessCodeLifespanUserAction,
.accessCodeLifespanMobile, .notBefore, .registrationAllowed,
.registrationEmailAsUsername, .rememberMe, .verifyEmail, .resetPasswordFlow,
.editUsernameAllowed, .bruteForceProtected, .permanentLockout, .maxFailureWaitSeconds,
.minimumQuickLoginWaitSeconds, .waitIncrementSeconds, .quickLoginCheckMilliSeconds,
.maxDeltaTimeSeconds, .failureFactor, .requiredCredentials, .otpPolicyType,
.otpPolicyAlgorithm, .otpPolicyInitialCounter, .otpPolicyDigits, .otpPolicyLookAheadWindow,
.otpPolicyPeriod, .otpSupportedApplications, .webAuthnPolicyRpEntityName,
.webAuthnPolicyAttestationConveyancePreference, .webAuthnPolicyAuthenticatorAttachment,
.webAuthnPolicyRequireResidentKey, .webAuthnPolicyUserVerificationRequirement,
.webAuthnPolicyCreateTimeout, .webAuthnPolicyAssertionTimeout,
.webAuthnPolicyRegistrationRecoveryEnabled, .webAuthnPolicyRegistrationRecoveryCodesQuantity,
.webAuthnPolicyRegistrationTokenBindingRequired, .webAuthnPolicyRegistrationAttestationConveyancePreference,
.webAuthnPolicyRegistrationAuthenticatorSelectionCriteria, .keys
)
| walk(if type == "object" then del(.id) else . end)' < "$INPUT_FILE" > "$OUTPUT_FILE"
echo "Minimal export saved to $OUTPUT_FILE"
```

### make the script executable
```bash
chmod +x clean-realm-config.sh
```

Now execute the script, making sure that you have inputed the correct file paths.
1 change: 1 addition & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ nav:
- Use Cases:
- Remote State Management: config/remote-state-management.md
- Adding Multiple post.logout.redirect.uris: config/addind-multiple-post-logout-redirect-uris.md
- Minimal Configurations From exported JSON: config/minimal-configuration.md


markdown_extensions:
Expand Down

0 comments on commit b6331fc

Please sign in to comment.