Skip to content

Commit

Permalink
Add configuration toggle to enable/disable use of OS native certifica…
Browse files Browse the repository at this point in the history
…te stores (#419)
  • Loading branch information
ChaitanyaKulkarni28 authored Aug 16, 2024
1 parent 4ffebd3 commit da50bde
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 0 deletions.
6 changes: 6 additions & 0 deletions google_guest_agent/agentcrypto/mtls_mds_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"os/exec"
"path/filepath"

"github.com/GoogleCloudPlatform/guest-agent/google_guest_agent/cfg"
"github.com/GoogleCloudPlatform/guest-agent/google_guest_agent/run"
"github.com/GoogleCloudPlatform/guest-agent/utils"
"github.com/GoogleCloudPlatform/guest-logging-go/logger"
Expand Down Expand Up @@ -59,6 +60,11 @@ func (j *CredsJob) writeRootCACert(ctx context.Context, content []byte, outputFi
return err
}

if cfg.Get().MDS.SkipNativeStore {
logger.Debugf("SkipNativeStore is enabled, will not write root cert to system store")
return nil
}

// Best effort to update system store, don't fail.
if err := updateSystemStore(ctx, outputFile); err != nil {
logger.Errorf("Failed add Root MDS cert to system trust store with error: %v", err)
Expand Down
4 changes: 4 additions & 0 deletions google_guest_agent/agentcrypto/mtls_mds_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,15 @@ import (
"path/filepath"
"testing"

"github.com/GoogleCloudPlatform/guest-agent/google_guest_agent/cfg"
"github.com/GoogleCloudPlatform/guest-agent/google_guest_agent/fakes"
"github.com/GoogleCloudPlatform/guest-agent/google_guest_agent/uefi"
)

func TestReadAndWriteRootCACert(t *testing.T) {
if err := cfg.Load(nil); err != nil {
t.Fatalf("Failed to load config: %v", err)
}
root := t.TempDir()
v := uefi.VariableName{Name: "testname", GUID: "testguid", RootDir: root}
j := &CredsJob{}
Expand Down
11 changes: 11 additions & 0 deletions google_guest_agent/agentcrypto/mtls_mds_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"syscall"
"unsafe"

"github.com/GoogleCloudPlatform/guest-agent/google_guest_agent/cfg"
"github.com/GoogleCloudPlatform/guest-agent/utils"
"github.com/GoogleCloudPlatform/guest-logging-go/logger"
"golang.org/x/sys/windows"
Expand Down Expand Up @@ -69,6 +70,11 @@ func (j *CredsJob) writeRootCACert(_ context.Context, cacert []byte, outputFile
return err
}

if cfg.Get().MDS.SkipNativeStore {
logger.Debugf("SkipNativeStore is enabled, will not write root cert to certstore")
return nil
}

x509Cert, err := parseCertificate(cacert)
if err != nil {
return fmt.Errorf("failed to parse root CA cert: %w", err)
Expand Down Expand Up @@ -189,6 +195,11 @@ func (j *CredsJob) writeClientCredentials(creds []byte, outputFile string) error
return fmt.Errorf("failed to write PFX file: %w", err)
}

if cfg.Get().MDS.SkipNativeStore {
logger.Debugf("SkipNativeStore is enabled, will not write client creds to certstore")
return nil
}

blob := windows.CryptDataBlob{
Size: uint32(len(pfx)),
Data: &pfx[0],
Expand Down
6 changes: 6 additions & 0 deletions google_guest_agent/cfg/cfg.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ cert_authentication = true
[MDS]
mtls_bootstrapping_enabled = true
skip_native_store = true
[Snapshots]
enabled = false
Expand Down Expand Up @@ -254,6 +255,11 @@ type OSLogin struct {
type MDS struct {
// MTLSBootstrappingEnabled enables/disables the mTLS credential refresher.
MTLSBootstrappingEnabled bool `ini:"mtls_bootstrapping_enabled,omitempty"`
// SkipNativeStore enables/disables the use of OSs native store. Native
// store is Certificate Store on Windows which hosts both Client Credential and
// Root certificate where as its trust store that hosts root certs like
// `/etc/pki/ca-trust/extracted/pem/tls-ca-bundle.pem` on Linux.
SkipNativeStore bool `ini:"skip_native_store,omitempty"`
}

// NetworkInterfaces contains the configurations of NetworkInterfaces section.
Expand Down

0 comments on commit da50bde

Please sign in to comment.