-
Notifications
You must be signed in to change notification settings - Fork 188
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of github.com:Evolveum/midpoint
* 'master' of github.com:Evolveum/midpoint: secrets providers: support for resolving secrets in BasicExpressionFunctions secrets providers: container/file/docker secrets provider
- Loading branch information
Showing
11 changed files
with
228 additions
and
73 deletions.
There are no files selected for viewing
75 changes: 75 additions & 0 deletions
75
...a/common/src/main/java/com/evolveum/midpoint/common/secrets/ContainerSecretsProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
/* | ||
* Copyright (C) 2010-2024 Evolveum and contributors | ||
* | ||
* This work is dual-licensed under the Apache License 2.0 | ||
* and European Union Public License. See LICENSE file for details. | ||
*/ | ||
|
||
package com.evolveum.midpoint.common.secrets; | ||
|
||
import java.io.File; | ||
import java.io.FileInputStream; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.nio.charset.Charset; | ||
import java.nio.charset.StandardCharsets; | ||
|
||
import org.apache.commons.io.IOUtils; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import com.evolveum.midpoint.prism.crypto.EncryptionException; | ||
import com.evolveum.midpoint.util.logging.Trace; | ||
import com.evolveum.midpoint.util.logging.TraceManager; | ||
import com.evolveum.midpoint.xml.ns._public.common.common_3.ContainerSecretsProviderType; | ||
|
||
public abstract class ContainerSecretsProvider<T extends ContainerSecretsProviderType> extends SecretsProviderImpl<T> { | ||
|
||
private static final Trace LOGGER = TraceManager.getTrace(ContainerSecretsProvider.class); | ||
|
||
private File parentDirectory; | ||
|
||
private Charset charset; | ||
|
||
public ContainerSecretsProvider(T configuration) { | ||
super(configuration); | ||
} | ||
|
||
@Override | ||
public void initialize() { | ||
super.initialize(); | ||
|
||
parentDirectory = getParentDirectory(); | ||
if (parentDirectory == null) { | ||
throw new IllegalStateException("No parent directory defined for secrets provider " + getIdentifier()); | ||
} | ||
|
||
T config = getConfiguration(); | ||
charset = config.getCharset() != null ? Charset.forName(config.getCharset()) : StandardCharsets.UTF_8; | ||
} | ||
|
||
protected abstract @NotNull File getParentDirectory(); | ||
|
||
@Override | ||
protected <ST> ST resolveSecret(@NotNull String key, @NotNull Class<ST> type) throws EncryptionException { | ||
// to avoid path traversal | ||
String filename = new File(key).getName(); | ||
File valueFile = new File(parentDirectory, filename); | ||
|
||
if (LOGGER.isTraceEnabled()) { | ||
LOGGER.trace("Reading secret from {}", valueFile.getAbsolutePath()); | ||
} | ||
|
||
ST value = null; | ||
if (valueFile.exists() && valueFile.isFile() && valueFile.canRead()) { | ||
try (InputStream is = new FileInputStream(valueFile)) { | ||
byte[] content = IOUtils.toByteArray(is); | ||
|
||
value = mapValue(content, type); | ||
} catch (IOException ex) { | ||
throw new EncryptionException("Couldn't read secret from " + valueFile.getAbsolutePath(), ex); | ||
} | ||
} | ||
|
||
return value; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
infra/common/src/main/java/com/evolveum/midpoint/common/secrets/FileSecretsProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* | ||
* Copyright (C) 2010-2024 Evolveum and contributors | ||
* | ||
* This work is dual-licensed under the Apache License 2.0 | ||
* and European Union Public License. See LICENSE file for details. | ||
*/ | ||
|
||
package com.evolveum.midpoint.common.secrets; | ||
|
||
import java.io.File; | ||
|
||
import org.jetbrains.annotations.NotNull; | ||
|
||
import com.evolveum.midpoint.util.exception.SystemException; | ||
import com.evolveum.midpoint.xml.ns._public.common.common_3.FileSecretsProviderType; | ||
|
||
public class FileSecretsProvider extends ContainerSecretsProvider<FileSecretsProviderType> { | ||
|
||
public FileSecretsProvider(@NotNull FileSecretsProviderType configuration) { | ||
super(configuration); | ||
} | ||
|
||
@Override | ||
protected @NotNull File getParentDirectory() { | ||
String parentDirectoryPath = getConfiguration().getParentDirectoryPath(); | ||
if (parentDirectoryPath == null) { | ||
throw new SystemException("No parent directory defined for secrets provider " + getIdentifier()); | ||
} | ||
|
||
return new File(parentDirectoryPath); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.