Search in sources :

Example 11 with KeyVaultSecret

use of com.azure.security.keyvault.secrets.models.KeyVaultSecret in project azure-credentials-plugin by jenkinsci.

the class ITSecretStringCredentials method getSecret.

@Test
public void getSecret() {
    final KeyVaultSecret secretBundle = createSecret("secret-string", "I'm secret");
    final String secretIdentifier = secretBundle.getId();
    // Verify configuration
    final SecretStringCredentials.DescriptorImpl descriptor = new SecretStringCredentials.DescriptorImpl();
    final FormValidation result = descriptor.doVerifyConfiguration(jenkinsAzureCredentialsId, secretIdentifier);
    Assert.assertEquals(FormValidation.Kind.OK, result.kind);
    // Get secret
    final SecretStringCredentials credentials = new SecretStringCredentials(CredentialsScope.SYSTEM, "", "", jenkinsAzureCredentialsId, secretIdentifier);
    final Secret secret = credentials.getSecret();
    Assert.assertEquals("I'm secret", secret.getPlainText());
}
Also used : KeyVaultSecret(com.azure.security.keyvault.secrets.models.KeyVaultSecret) Secret(hudson.util.Secret) KeyVaultSecret(com.azure.security.keyvault.secrets.models.KeyVaultSecret) FormValidation(hudson.util.FormValidation) SecretStringCredentials(com.microsoft.jenkins.keyvault.SecretStringCredentials) Test(org.junit.Test)

Example 12 with KeyVaultSecret

use of com.azure.security.keyvault.secrets.models.KeyVaultSecret in project azure-credentials-plugin by jenkinsci.

the class KeyVaultIntegrationTestBase method createSecret.

protected KeyVaultSecret createSecret(final String name, final String value) {
    KeyVaultSecret keyVaultSecret = new KeyVaultSecret(name, value);
    ClientSecretCredential clientSecretCredential = new ClientSecretCredentialBuilder().clientId(testEnv.clientId).clientSecret(testEnv.clientSecret).tenantId(testEnv.tenantId).build();
    SecretClient secretClient = AzureCredentials.createKeyVaultClient(clientSecretCredential, vaultUri);
    return secretClient.setSecret(keyVaultSecret);
}
Also used : KeyVaultSecret(com.azure.security.keyvault.secrets.models.KeyVaultSecret) ClientSecretCredentialBuilder(com.azure.identity.ClientSecretCredentialBuilder) ClientSecretCredential(com.azure.identity.ClientSecretCredential) SecretClient(com.azure.security.keyvault.secrets.SecretClient)

Example 13 with KeyVaultSecret

use of com.azure.security.keyvault.secrets.models.KeyVaultSecret in project azure-keyvault-plugin by jenkinsci.

the class AzureKeyVaultBuildWrapper method setUp.

public void setUp(Context context, Run<?, ?> build, FilePath workspace, Launcher launcher, TaskListener listener, EnvVars initialEnvironment) {
    if (azureKeyVaultSecrets == null || azureKeyVaultSecrets.isEmpty()) {
        return;
    }
    SecretClient client = AzureCredentials.createKeyVaultClient(getKeyVaultCredential(build), getKeyVaultURL());
    for (AzureKeyVaultSecret secret : azureKeyVaultSecrets) {
        if (secret.isPassword()) {
            KeyVaultSecret bundle = getSecret(client, secret);
            if (bundle != null) {
                valuesToMask.add(bundle.getValue());
                context.env(secret.getEnvVariable(), bundle.getValue());
            } else {
                throw new AzureKeyVaultException(format("Secret: %s not found in vault: %s", secret.getName(), getKeyVaultURL()));
            }
        } else if (secret.isCertificate()) {
            // Get Certificate from Keyvault as a Secret
            KeyVaultSecret bundle = getSecret(client, secret);
            if (bundle != null) {
                try {
                    String path = AzureKeyVaultUtil.convertAndWritePfxToDisk(workspace, bundle.getValue());
                    context.env(secret.getEnvVariable(), path);
                } catch (Exception e) {
                    throw new AzureKeyVaultException(e.getMessage(), e);
                }
            } else {
                throw new AzureKeyVaultException(format("Certificate: %s not found in vault: %s", secret.getName(), getKeyVaultURL()));
            }
        }
    }
}
Also used : KeyVaultSecret(com.azure.security.keyvault.secrets.models.KeyVaultSecret) SecretClient(com.azure.security.keyvault.secrets.SecretClient)

Example 14 with KeyVaultSecret

use of com.azure.security.keyvault.secrets.models.KeyVaultSecret in project lowkey-vault by nagyesta.

the class SecretsStepDefs method theSecretNamedNameIsRestored.

@And("the secret named {name} is restored")
public void theSecretNamedNameIsRestored(final String name) {
    final byte[] bytes = context.getBackupBytes(name);
    final KeyVaultSecret secret = context.getClient(context.getSecretServiceVersion()).restoreSecretBackup(bytes);
    context.addFetchedSecret(name, secret);
}
Also used : KeyVaultSecret(com.azure.security.keyvault.secrets.models.KeyVaultSecret) And(io.cucumber.java.en.And)

Example 15 with KeyVaultSecret

use of com.azure.security.keyvault.secrets.models.KeyVaultSecret in project lowkey-vault by nagyesta.

the class SecretsStepDefs method fetchLatestSecretVersion.

@When("the last secret version of {name} is fetched without providing a version")
public void fetchLatestSecretVersion(final String name) {
    final KeyVaultSecret secret = context.getClient(context.getSecretServiceVersion()).getSecret(name);
    final List<KeyVaultSecret> versionsCreated = context.getCreatedEntities().get(name);
    final String expectedLastVersionId = versionsCreated.get(versionsCreated.size() - 1).getId();
    context.addFetchedSecret(name, secret);
    assertEquals(expectedLastVersionId, secret.getId());
}
Also used : KeyVaultSecret(com.azure.security.keyvault.secrets.models.KeyVaultSecret) When(io.cucumber.java.en.When)

Aggregations

KeyVaultSecret (com.azure.security.keyvault.secrets.models.KeyVaultSecret)19 Test (org.junit.Test)6 When (io.cucumber.java.en.When)5 SecretClient (com.azure.security.keyvault.secrets.SecretClient)4 FormValidation (hudson.util.FormValidation)3 Secret (hudson.util.Secret)3 ResourceNotFoundException (com.azure.core.exception.ResourceNotFoundException)2 SecretCertificateCredentials (com.microsoft.jenkins.keyvault.SecretCertificateCredentials)2 KeyStore (java.security.KeyStore)2 TokenCredential (com.azure.core.credential.TokenCredential)1 FixedDelay (com.azure.core.http.policy.FixedDelay)1 RetryPolicy (com.azure.core.http.policy.RetryPolicy)1 ClientSecretCredential (com.azure.identity.ClientSecretCredential)1 ClientSecretCredentialBuilder (com.azure.identity.ClientSecretCredentialBuilder)1 SecretClientBuilder (com.azure.security.keyvault.secrets.SecretClientBuilder)1 DeletedSecret (com.azure.security.keyvault.secrets.models.DeletedSecret)1 SecretProperties (com.azure.security.keyvault.secrets.models.SecretProperties)1 SecretStringCredentials (com.microsoft.jenkins.keyvault.SecretStringCredentials)1 VaultSecretNotFoundException (com.quorum.tessera.key.vault.VaultSecretNotFoundException)1 NonNull (edu.umd.cs.findbugs.annotations.NonNull)1