Skip to content

Commit 5547f93

Browse files
Fixed SaaS related issues for GCP credetnials
1 parent 534a06c commit 5547f93

5 files changed

Lines changed: 42 additions & 6 deletions

File tree

GCPCAS/Client/GCPCASClient.cs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@ public class GCPCASClient : IGCPCASClient
5858
/// <param name="projectId">The GCP project ID where the target GCP CAS CA is located</param>
5959
/// <param name="caPool">The CA Pool ID in GCP CAS to use for certificate operations. If the CA Pool has resource name <c>projects/my-project/locations/us-central1/caPools/my-pool</c>, this field should be set to <c>my-pool</c></param>
6060
/// <param name="caId">The CA ID of a CA in the same CA Pool as CAPool. For example, to issue certificates from a CA with resource name <c>projects/my-project/locations/us-central1/caPools/my-pool/certificateAuthorities/my-ca</c>, this field should be set to <c>my-ca</c>.</param>
61-
public GCPCASClient(string locationId, string projectId, string caPool, string caId)
61+
/// <param name="serviceAccountKey">Optional JSON service account key. When provided, used instead of Application Default Credentials.</param>
62+
public GCPCASClient(string locationId, string projectId, string caPool, string caId, string serviceAccountKey = null)
6263
{
6364
_logger = LogHandler.GetClassLogger<GCPCASClient>();
6465
_logger.MethodEntry();
@@ -69,8 +70,18 @@ public GCPCASClient(string locationId, string projectId, string caPool, string c
6970
this._caPool = caPool;
7071
this._caId = caId;
7172

72-
_logger.LogTrace($"Setting up a {typeof(CertificateAuthorityServiceClient).ToString()} using the Default gRPC adapter");
73-
_client = new CertificateAuthorityServiceClientBuilder().Build();
73+
var builder = new CertificateAuthorityServiceClientBuilder();
74+
if (!string.IsNullOrEmpty(serviceAccountKey))
75+
{
76+
_logger.LogTrace("Using provided service account key JSON for authentication");
77+
builder.JsonCredentials = serviceAccountKey;
78+
}
79+
else
80+
{
81+
_logger.LogTrace($"Setting up a {typeof(CertificateAuthorityServiceClient).ToString()} using Application Default Credentials");
82+
}
83+
84+
_client = builder.Build();
7485
_logger.MethodExit();
7586
}
7687

GCPCAS/GCPCASCAPlugin.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ private void GCPCASClientFromCAConnectionData(Dictionary<string, object> connect
200200
else
201201
{
202202
_logger.LogDebug("Creating new GCPCASClient instance.");
203-
Client = new GCPCASClient(_config.LocationId, _config.ProjectId, _config.CAPool, _config.CAId);
203+
Client = new GCPCASClient(_config.LocationId, _config.ProjectId, _config.CAPool, _config.CAId, _config.ServiceAccountKey);
204204
}
205205

206206
if (_config.Enabled)

GCPCAS/GCPCASCAPluginConfig.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ public class ConfigConstants
3333
public const string CAPool = "CAPool";
3434
public const string CAId = "CAId";
3535
public const string Enabled = "Enabled";
36+
public const string ServiceAccountKey = "ServiceAccountKey";
3637
}
3738

3839
public class Config
@@ -42,6 +43,7 @@ public class Config
4243
public string CAPool { get; set; }
4344
public string CAId { get; set; }
4445
public bool Enabled { get; set; }
46+
public string ServiceAccountKey { get; set; }
4547
}
4648

4749
public static class EnrollmentParametersConstants
@@ -88,6 +90,13 @@ public static Dictionary<string, PropertyConfigInfo> GetPluginAnnotations()
8890
DefaultValue = true,
8991
Type = "Boolean"
9092
},
93+
[ConfigConstants.ServiceAccountKey] = new PropertyConfigInfo()
94+
{
95+
Comments = "Optional JSON service account key for GCP authentication. When provided, this is used instead of Application Default Credentials (ADC). This is recommended for containerized environments where mounting a credentials file is not practical. Leave empty to use ADC.",
96+
Hidden = false,
97+
DefaultValue = "",
98+
Type = "String"
99+
},
91100
};
92101
}
93102

docsource/configuration.md

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,19 @@ The [Google Cloud Platform (GCP) CA Services (CAS)](https://cloud.google.com/sec
1919
2020
## Requirements
2121

22-
### Application Default Credentials
22+
### GCP Authentication
2323

24-
The GCP CAS AnyCA Gateway REST plugin connects to and authenticates with GCP CAS implicitly using [Application Default Credentials](https://cloud.google.com/docs/authentication/application-default-credentials). This means that all authentication-related configuration of the GCP CAS AnyCA Gateway REST plugin is implied by the environment where the AnyCA Gateway REST itself is running.
24+
The GCP CAS AnyCA Gateway REST plugin supports two methods for authenticating with GCP CAS:
25+
26+
#### Option 1: Service Account Key via CA Connection Configuration (Recommended for Containers)
27+
28+
The plugin accepts an optional **ServiceAccountKey** field in the CA Connection configuration. When provided, the JSON service account key is used directly for authentication without requiring any credential files on the filesystem. This is the recommended approach for containerized deployments (e.g., Docker, Kubernetes) where mounting credential files is not practical.
29+
30+
To use this method, paste the full JSON contents of a GCP service account key into the **ServiceAccountKey** field in the CA Connection tab. In Kubernetes, the service account key JSON can be stored as a Secret and injected via the Keyfactor configuration API.
31+
32+
#### Option 2: Application Default Credentials (ADC)
33+
34+
If the **ServiceAccountKey** field is left empty, the plugin falls back to [Application Default Credentials](https://cloud.google.com/docs/authentication/application-default-credentials). This means that all authentication-related configuration is implied by the environment where the AnyCA Gateway REST itself is running.
2535

2636
Please refer to [Google's documentation](https://cloud.google.com/docs/authentication/provide-credentials-adc) to configure ADC on the server running the AnyCA Gateway REST.
2737

@@ -32,6 +42,8 @@ Please refer to [Google's documentation](https://cloud.google.com/docs/authentic
3242
> 1. The service account that the AnyCA Gateway REST runs under must have read permission to the GCP credential JSON file.
3343
> 2. You must set the `GOOGLE_APPLICATION_CREDENTIALS` environment variable for the Windows Service running the AnyCA Gateway REST using the [Windows registry editor](https://learn.microsoft.com/en-us/troubleshoot/windows-server/performance/windows-registry-advanced-users).
3444
> * Refer to the [HKLM\SYSTEM\CurrentControlSet\Services Registry Tree](https://learn.microsoft.com/en-us/windows-hardware/drivers/install/hklm-system-currentcontrolset-services-registry-tree) docs
45+
>
46+
> For containerized environments running on GCP (e.g., GKE), [Workload Identity](https://cloud.google.com/kubernetes-engine/docs/how-to/workload-identity) can be used instead, which requires no credential files or environment variables.
3547
3648
If the selected ADC mechanism is [Service Account Key](https://cloud.google.com/docs/authentication/provide-credentials-adc#wlif-key), it's recommended that a [custom role is created](https://cloud.google.com/iam/docs/creating-custom-roles) that has the following minimum permissions:
3749

integration-manifest.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@
3232
{
3333
"name": "Enabled",
3434
"description": "Flag to Enable or Disable gateway functionality. Disabling is primarily used to allow creation of the CA prior to configuration information being available."
35+
},
36+
{
37+
"name": "ServiceAccountKey",
38+
"description": "Optional JSON service account key for GCP authentication. When provided, this is used instead of Application Default Credentials (ADC). Recommended for containerized environments where mounting a credentials file is not practical. Leave empty to use ADC."
3539
}
3640
],
3741
"enrollment_config": [

0 commit comments

Comments
 (0)