@@ -879,31 +879,32 @@ public AuthResponse loginByGithub(final String githubToken, final String githubA
879
879
}
880
880
881
881
/**
882
- * <p>Basic login operation to authenticate to an GCP backend. Example usage:</p>
882
+ * <p>Basic login operation to authenticate to an JWT backend. Example usage:</p>
883
883
*
884
884
* <blockquote>
885
885
* <pre>{@code
886
- * final AuthResponse response = vault.auth().loginByGCP( "dev", "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...");
886
+ * final AuthResponse response = vault.auth().loginByJwt("kubernetes", "dev", "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...");
887
887
*
888
888
* final String token = response.getAuthClientToken();
889
889
* }</pre>
890
890
* </blockquote>
891
891
*
892
+ * @param provider Provider of JWT token.
892
893
* @param role The gcp role used for authentication
893
894
* @param jwt The JWT token for the role
894
895
* @return The auth token, with additional response metadata
895
896
* @throws VaultException If any error occurs, or unexpected response received from Vault
896
897
*/
897
898
// TODO: Needs integration test coverage if possible
898
- public AuthResponse loginByGCP ( final String role , final String jwt ) throws VaultException {
899
+ public AuthResponse loginByJwt ( final String provider , final String role , final String jwt ) throws VaultException {
899
900
int retryCount = 0 ;
900
901
901
902
while (true ) {
902
903
try {
903
904
// HTTP request to Vault
904
905
final String requestJson = Json .object ().add ("role" , role ).add ("jwt" , jwt ).toString ();
905
906
final RestResponse restResponse = new Rest ()
906
- .url (config .getAddress () + "/v1/auth/gcp /login" )
907
+ .url (config .getAddress () + "/v1/auth/" + provider + " /login" )
907
908
.optionalHeader ("X-Vault-Namespace" , this .nameSpace )
908
909
.body (requestJson .getBytes (StandardCharsets .UTF_8 ))
909
910
.connectTimeoutSeconds (config .getOpenTimeout ())
@@ -941,6 +942,50 @@ public AuthResponse loginByGCP(final String role, final String jwt) throws Vault
941
942
}
942
943
}
943
944
945
+
946
+ /**
947
+ * <p>Basic login operation to authenticate to an GCP backend. Example usage:</p>
948
+ *
949
+ * <blockquote>
950
+ * <pre>{@code
951
+ * final AuthResponse response = vault.auth().loginByGCP("dev", "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...");
952
+ *
953
+ * final String token = response.getAuthClientToken();
954
+ * }</pre>
955
+ * </blockquote>
956
+ *
957
+ * @param role The gcp role used for authentication
958
+ * @param jwt The JWT token for the role
959
+ * @return The auth token, with additional response metadata
960
+ * @throws VaultException If any error occurs, or unexpected response received from Vault
961
+ */
962
+ public AuthResponse loginByGCP (final String role , final String jwt ) throws VaultException {
963
+ return loginByJwt ("gcp" , role , jwt );
964
+ }
965
+
966
+
967
+ /**
968
+ * Basic login operation to authenticate to an kubernetes backend. Example usage:
969
+ *
970
+ * <blockquote>
971
+ *
972
+ * <pre>{@code
973
+ * final AuthResponse response =
974
+ * vault.auth().loginByKubernetes("dev", "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...");
975
+ *
976
+ * final String token = response.getAuthClientToken();
977
+ * }</pre>
978
+ * </blockquote>
979
+ *
980
+ * @param role The kubernetes role used for authentication
981
+ * @param jwt The JWT token for the role, typically read from /var/run/secrets/kubernetes.io/serviceaccount/token
982
+ * @return The auth token, with additional response metadata
983
+ * @throws VaultException If any error occurs, or unexpected response received from Vault
984
+ */
985
+ public AuthResponse loginByKubernetes (final String role , final String jwt ) throws VaultException {
986
+ return loginByJwt ("kubernetes" , role , jwt );
987
+ }
988
+
944
989
/**
945
990
* <p>Basic login operation to authenticate using Vault's TLS Certificate auth backend. Example usage:</p>
946
991
*
0 commit comments