-
Notifications
You must be signed in to change notification settings - Fork 41
feat: add PKI HSM option #270
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,6 +6,7 @@ import ( | |
| "os" | ||
| "os/exec" | ||
| "os/signal" | ||
| "path/filepath" | ||
| "runtime" | ||
| "sync/atomic" | ||
| "syscall" | ||
|
|
@@ -401,11 +402,26 @@ var gatewayStartCmd = &cobra.Command{ | |
| } | ||
| } | ||
|
|
||
| pkcs11ModulePath, _ := cmd.Flags().GetString("pkcs11-module") | ||
| if pkcs11ModulePath != "" { | ||
| if !filepath.IsAbs(pkcs11ModulePath) { | ||
| util.HandleError(fmt.Errorf("--pkcs11-module must be an absolute path (got %q)", pkcs11ModulePath), "unable to load PKCS#11 driver") | ||
| } | ||
| info, statErr := os.Stat(pkcs11ModulePath) | ||
| if statErr != nil { | ||
| util.HandleError(fmt.Errorf("PKCS#11 driver not found at %q: %w", pkcs11ModulePath, statErr), "unable to load PKCS#11 driver") | ||
| } | ||
| if info.IsDir() { | ||
| util.HandleError(fmt.Errorf("--pkcs11-module path is a directory, expected a driver file: %q", pkcs11ModulePath), "unable to load PKCS#11 driver") | ||
| } | ||
| } | ||
|
|
||
| gatewayInstance, err := gatewayv2.NewGateway(&gatewayv2.GatewayConfig{ | ||
| Name: gatewayName, | ||
| RelayName: relayName, | ||
| ReconnectDelay: 10 * time.Second, | ||
| UseV3Connect: runningWithStoredToken, | ||
| Name: gatewayName, | ||
| RelayName: relayName, | ||
| ReconnectDelay: 10 * time.Second, | ||
| UseV3Connect: runningWithStoredToken, | ||
| Pkcs11ModulePath: pkcs11ModulePath, | ||
| }) | ||
|
|
||
| if err != nil { | ||
|
|
@@ -759,6 +775,7 @@ func init() { | |
| gatewayStartCmd.Flags().String("service-account-key-file-path", "", "service account key file path for GCP IAM auth") | ||
| gatewayStartCmd.Flags().String("jwt", "", "JWT for jwt-based auth methods [oidc-auth, jwt-auth]") | ||
| gatewayStartCmd.Flags().String("pam-session-recording-path", "", "directory path for PAM session recordings (defaults to /var/lib/infisical/session_recordings)") | ||
| gatewayStartCmd.Flags().String("pkcs11-module", "", "absolute path to a PKCS#11 driver (e.g. /opt/fortanix/pkcs11/fortanix_pkcs11.so). When set, the gateway loads the driver, advertises pkcs11 capability on heartbeat, and serves HSM operations.") | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no need to mention heartbeat here since that's just an internal detail |
||
|
|
||
| // Legacy install command flags (v1) | ||
| gatewayInstallCmd.Flags().String("token", "", "Connect with Infisical using machine identity access token") | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| package gatewayv2 | ||
|
|
||
| type Pkcs11Module interface { | ||
| Test(slotLabel string, pin []byte) (SlotInfo, error) | ||
|
|
||
| GenerateKeyPair(slotLabel string, pin []byte, keyLabel string, keyAlgorithm string) ([]byte, error) | ||
|
|
||
| GetPublicKey(slotLabel string, pin []byte, keyLabel string) ([]byte, error) | ||
|
|
||
| Sign(slotLabel string, pin []byte, keyLabel string, mechanism string, data []byte, isDigest bool) ([]byte, error) | ||
|
|
||
| Finalize() error | ||
| } | ||
|
|
||
| type SlotInfo struct { | ||
| Manufacturer string `json:"manufacturer"` | ||
| Model string `json:"model"` | ||
| Firmware string `json:"firmware"` | ||
| } | ||
|
|
||
| type Pkcs11ErrorCode string | ||
|
|
||
| const ( | ||
| Pkcs11ErrPinIncorrect Pkcs11ErrorCode = "pin_incorrect" | ||
| Pkcs11ErrPinLocked Pkcs11ErrorCode = "pin_locked" | ||
| Pkcs11ErrSlotNotFound Pkcs11ErrorCode = "slot_not_found" | ||
| Pkcs11ErrKeyNotFound Pkcs11ErrorCode = "key_not_found" | ||
| Pkcs11ErrMechanismInvalid Pkcs11ErrorCode = "mechanism_invalid" | ||
| Pkcs11ErrDriverUnavailable Pkcs11ErrorCode = "driver_unavailable" | ||
| Pkcs11ErrLoginFailed Pkcs11ErrorCode = "login_failed" | ||
| Pkcs11ErrNotSupported Pkcs11ErrorCode = "pkcs11_not_supported" | ||
| Pkcs11ErrBadRequest Pkcs11ErrorCode = "bad_request" | ||
| Pkcs11ErrInternal Pkcs11ErrorCode = "internal" | ||
| ) | ||
|
|
||
| type Pkcs11Error struct { | ||
| Code Pkcs11ErrorCode | ||
| Message string | ||
| } | ||
|
|
||
| func (e *Pkcs11Error) Error() string { | ||
| return string(e.Code) + ": " + e.Message | ||
| } | ||
|
|
||
| // Supported keyAlgorithm values. | ||
| const ( | ||
| KeyAlgorithmRSA2048 = "RSA_2048" | ||
| KeyAlgorithmRSA4096 = "RSA_4096" | ||
| KeyAlgorithmECCP256 = "ECC_P256" | ||
| KeyAlgorithmECCP384 = "ECC_P384" | ||
| ) | ||
|
|
||
| const CapabilityPkcs11 = "pkcs11" |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| //go:build !pkcs11 | ||
|
|
||
| package gatewayv2 | ||
|
|
||
| func LoadPkcs11Module(_ string) (Pkcs11Module, error) { | ||
| return nil, &Pkcs11Error{ | ||
| Code: Pkcs11ErrNotSupported, | ||
| Message: "This Gateway build was compiled without PKCS#11 support. Use the infisical-pkcs11 release artifact, or build from source with `go build -tags pkcs11` (cgo + dynamic linking required).", | ||
| } | ||
| } | ||
|
Comment on lines
+1
to
+10
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. hold on.. why again do we need this? I thought it would just be one CLI distribution? |
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same Q here.. why would we need this?