-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add SecretManager in anticipation of more secret managers
Add SecretManager in anticipation of more secret managers
- Loading branch information
Showing
15 changed files
with
152 additions
and
39 deletions.
There are no files selected for viewing
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
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
37 changes: 37 additions & 0 deletions
37
cdi-core/src/main/java/com/linkedin/cdi/util/GobblinSecretManager.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,37 @@ | ||
// Copyright 2021 LinkedIn Corporation. All rights reserved. | ||
// Licensed under the BSD-2 Clause license. | ||
// See LICENSE in the project root for license information. | ||
|
||
package com.linkedin.cdi.util; | ||
|
||
import org.apache.gobblin.configuration.State; | ||
|
||
|
||
/** | ||
* Interface for secret encryption and decryption | ||
*/ | ||
public class GobblinSecretManager extends SecretManager { | ||
public GobblinSecretManager(State state) { | ||
super(state); | ||
} | ||
|
||
/** | ||
* Decrypt the encrypted string | ||
* @param input the encrypted string | ||
* @return decrypted string | ||
*/ | ||
@Override | ||
public String decrypt(String input) { | ||
return EncryptionUtils.decryptGobblin(input, state); | ||
} | ||
|
||
/** | ||
* Encrypt the decrypted string | ||
* @param input the unencrypted string | ||
* @return encrypted string | ||
*/ | ||
@Override | ||
public String encrypt(String input) { | ||
return EncryptionUtils.encryptGobblin(input, state); | ||
} | ||
} |
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
59 changes: 59 additions & 0 deletions
59
cdi-core/src/main/java/com/linkedin/cdi/util/SecretManager.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,59 @@ | ||
// Copyright 2021 LinkedIn Corporation. All rights reserved. | ||
// Licensed under the BSD-2 Clause license. | ||
// See LICENSE in the project root for license information. | ||
|
||
package com.linkedin.cdi.util; | ||
|
||
import org.apache.gobblin.configuration.State; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import static com.linkedin.cdi.configuration.PropertyCollection.*; | ||
|
||
|
||
/** | ||
* Interface for secret encryption and decryption | ||
*/ | ||
public abstract class SecretManager { | ||
final private static Logger LOG = LoggerFactory.getLogger(SecretManager.class); | ||
private static SecretManager manager = null; | ||
protected State state; | ||
|
||
public SecretManager(State state) { | ||
this.state = state; | ||
} | ||
/** | ||
* Decrypt the encrypted string | ||
* @param input the encrypted string | ||
* @return decrypted string | ||
*/ | ||
abstract public String decrypt(String input); | ||
|
||
/** | ||
* Encrypt the decrypted string | ||
* @param input the unencrypted string | ||
* @return encrypted string | ||
*/ | ||
abstract public String encrypt(String input); | ||
|
||
static public SecretManager getInstance(State state) { | ||
if (SecretManager.manager != null) { | ||
return SecretManager.manager; | ||
} | ||
|
||
try { | ||
Class<?> clazz = Class.forName(MSTAGE_SECRET_MANAGER_CLASS.get(state)); | ||
Object manager = clazz.getConstructor(State.class).newInstance(state); | ||
if (manager instanceof SecretManager) { | ||
SecretManager.manager = (SecretManager) manager; | ||
} | ||
} catch (RuntimeException re) { | ||
throw re; | ||
} catch (Exception e) { | ||
LOG.error("Error creating required secret manager: {}", MSTAGE_SECRET_MANAGER_CLASS.get(state)); | ||
LOG.info("Returning default GobblinSecretManager."); | ||
SecretManager.manager = new GobblinSecretManager(state); | ||
} | ||
return SecretManager.manager; | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# ms.secret.manager.class | ||
|
||
**Tags**: | ||
|
||
**Type**: string | ||
|
||
**Default value**: `com.linkedin.cdi.util.GobblinSecretManager` | ||
|
||
**Related**: | ||
|
||
## Description | ||
|
||
`ms.secret.manager.class` specifies the SecretManager class to use for secrets | ||
and confidential data encryption and decryption. | ||
|
||
Secrets include usernames, passwords, API keys, tokens, etc, that are essential for connections to other | ||
data systems. | ||
|
||
Confidential data include dataset columns that require encryption on storage. | ||
|
||
Currently, we have the following SecretManager: | ||
|
||
- `com.linkedin.cdi.util.GobblinSecretManager` | ||
|
||
[back to summary](summary.md#mssecretmanagerclass) |
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