use of com.cloudera.thunderhead.service.usermanagement.UserManagementProto.ActorKerberosKey in project cloudbreak by hortonworks.
the class UserKeytabService method getKeytabBase64.
public String getKeytabBase64(String userCrn, String environmentCrn) {
String userAccountId = Crn.safeFromString(userCrn).getAccountId();
validateSameAccount(userAccountId, environmentCrn);
String realm = getKerberosRealm(userAccountId, environmentCrn);
GetActorWorkloadCredentialsResponse getActorWorkloadCredentialsResponse = grpcUmsClient.getActorWorkloadCredentials(userCrn, MDCUtils.getRequestId(), regionAwareInternalCrnGeneratorFactory);
validateHasCredentials(getActorWorkloadCredentialsResponse);
String workloadUsername = getActorWorkloadCredentialsResponse.getWorkloadUsername();
validateFreeIpaState(workloadUsername, environmentCrn);
List<ActorKerberosKey> actorKerberosKeys = getActorWorkloadCredentialsResponse.getKerberosKeysList();
return userKeytabGenerator.generateKeytabBase64(workloadUsername, realm, actorKerberosKeys);
}
use of com.cloudera.thunderhead.service.usermanagement.UserManagementProto.ActorKerberosKey in project cloudbreak by hortonworks.
the class KrbKeySetEncoder method getASNEncodedKrbPrincipalKey.
public static String getASNEncodedKrbPrincipalKey(List<ActorKerberosKey> keys) throws IOException {
ASN1Encodable[] asn1Encodables = new ASN1Encodable[keys.size()];
for (int i = 0; i < keys.size(); i++) {
ActorKerberosKey key = keys.get(i);
byte[] byteValue = Base64.getDecoder().decode(key.getKeyValue().getBytes(StandardCharsets.UTF_8));
asn1Encodables[i] = makeKrbKey(makeSalt(key.getSaltType(), key.getSaltValue()), makeEncryptionKey(key.getKeyType(), byteValue));
}
DERSequence krbKeys = new DERSequence(asn1Encodables);
DERSequence krbKeySet = new DERSequence(new ASN1Encodable[] { // attribute-major-vno
new DERTaggedObject(true, TAG_ATTRIBUTE_MAJOR_VNO, new ASN1Integer(1)), // attribute-minor-vno
new DERTaggedObject(true, TAG_ATTRIBUTE_MINOR_VNO, new ASN1Integer(1)), // kvno
new DERTaggedObject(true, TAG_KVNO, new ASN1Integer(1)), // mkvno
new DERTaggedObject(true, TAG_MKVNO, new ASN1Integer(1)), new DERTaggedObject(true, TAG_KEYS, krbKeys) });
return Base64.getEncoder().encodeToString(krbKeySet.getEncoded());
}
use of com.cloudera.thunderhead.service.usermanagement.UserManagementProto.ActorKerberosKey in project cloudbreak by hortonworks.
the class UserKeytabServiceTest method newActorKerberosKeys.
private static List<ActorKerberosKey> newActorKerberosKeys() {
ActorKerberosKey key1 = ActorKerberosKey.newBuilder().build();
ActorKerberosKey key2 = ActorKerberosKey.newBuilder().build();
return List.of(key1, key2);
}
use of com.cloudera.thunderhead.service.usermanagement.UserManagementProto.ActorKerberosKey in project cloudbreak by hortonworks.
the class UserKeytabGenerator method generateKeytabBase64.
public String generateKeytabBase64(String username, String realm, List<ActorKerberosKey> actorKerberosKeys) {
LOGGER.info("Generating keytab for username = {} with realm = {}", username, realm);
if (actorKerberosKeys.isEmpty()) {
throw new IllegalArgumentException("Expected at least 1 actorKerberosKeys");
}
List<KeytabEntry> keytabEntries = actorKerberosKeys.stream().map(key -> toKeytabEntry(username, realm, key)).collect(Collectors.toList());
Keytab keytab = new Keytab();
keytab.addKeytabEntries(keytabEntries);
try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) {
keytab.store(outputStream);
byte[] keyBytes = outputStream.toByteArray();
return Base64.getEncoder().encodeToString(keyBytes);
} catch (IOException e) {
throw new RuntimeException("Failed to generate keytab", e);
}
}
Aggregations