mirror of
				https://github.com/optim-enterprises-bv/vault.git
				synced 2025-10-30 02:02:43 +00:00 
			
		
		
		
	Support mlock and custom tmpdir for containerized plugins (#23215)
This commit is contained in:
		
							
								
								
									
										6
									
								
								changelog/23215.txt
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										6
									
								
								changelog/23215.txt
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,6 @@ | ||||
| ```release-note:bug | ||||
| plugins: Containerized plugins can be run with mlock enabled. | ||||
| ``` | ||||
| ```release-note:improvement | ||||
| plugins: Containerized plugins can be configured to still work when running with systemd's PrivateTmp=true setting. | ||||
| ``` | ||||
							
								
								
									
										4
									
								
								go.mod
									
									
									
									
									
								
							
							
						
						
									
										4
									
								
								go.mod
									
									
									
									
									
								
							| @@ -97,7 +97,7 @@ require ( | ||||
| 	github.com/hashicorp/go-memdb v1.3.4 | ||||
| 	github.com/hashicorp/go-msgpack v1.1.5 | ||||
| 	github.com/hashicorp/go-multierror v1.1.1 | ||||
| 	github.com/hashicorp/go-plugin v1.5.1 | ||||
| 	github.com/hashicorp/go-plugin v1.5.2 | ||||
| 	github.com/hashicorp/go-raftchunking v0.6.3-0.20191002164813-7e9e8525653a | ||||
| 	github.com/hashicorp/go-retryablehttp v0.7.4 | ||||
| 	github.com/hashicorp/go-rootcerts v1.0.2 | ||||
| @@ -386,7 +386,7 @@ require ( | ||||
| 	github.com/hashicorp/go-metrics v0.5.1 // indirect | ||||
| 	github.com/hashicorp/go-msgpack/v2 v2.0.0 // indirect | ||||
| 	github.com/hashicorp/go-secure-stdlib/fileutil v0.1.0 // indirect | ||||
| 	github.com/hashicorp/go-secure-stdlib/plugincontainer v0.2.1 // indirect | ||||
| 	github.com/hashicorp/go-secure-stdlib/plugincontainer v0.2.2 // indirect | ||||
| 	github.com/hashicorp/go-slug v0.12.1 // indirect | ||||
| 	github.com/hashicorp/go-tfe v1.33.0 // indirect | ||||
| 	github.com/hashicorp/jsonapi v0.0.0-20210826224640-ee7dae0fb22d // indirect | ||||
|   | ||||
							
								
								
									
										7
									
								
								go.sum
									
									
									
									
									
								
							
							
						
						
									
										7
									
								
								go.sum
									
									
									
									
									
								
							| @@ -2012,8 +2012,9 @@ github.com/hashicorp/go-multierror v1.0.0/go.mod h1:dHtQlpGsu+cZNNAkkCN/P3hoUDHh | ||||
| github.com/hashicorp/go-multierror v1.1.0/go.mod h1:spPvp8C1qA32ftKqdAHm4hHTbPw+vmowP0z+KUhOZdA= | ||||
| github.com/hashicorp/go-multierror v1.1.1 h1:H5DkEtf6CXdFp0N0Em5UCwQpXMWke8IA0+lD48awMYo= | ||||
| github.com/hashicorp/go-multierror v1.1.1/go.mod h1:iw975J/qwKPdAO1clOe2L8331t/9/fmwbPZ6JB6eMoM= | ||||
| github.com/hashicorp/go-plugin v1.5.1 h1:oGm7cWBaYIp3lJpx1RUEfLWophprE2EV/KUeqBYo+6k= | ||||
| github.com/hashicorp/go-plugin v1.5.1/go.mod h1:w1sAEES3g3PuV/RzUrgow20W2uErMly84hhD3um1WL4= | ||||
| github.com/hashicorp/go-plugin v1.5.2 h1:aWv8eimFqWlsEiMrYZdPYl+FdHaBJSN4AWwGWfT1G2Y= | ||||
| github.com/hashicorp/go-plugin v1.5.2/go.mod h1:w1sAEES3g3PuV/RzUrgow20W2uErMly84hhD3um1WL4= | ||||
| github.com/hashicorp/go-raftchunking v0.6.3-0.20191002164813-7e9e8525653a h1:FmnBDwGwlTgugDGbVxwV8UavqSMACbGrUpfc98yFLR4= | ||||
| github.com/hashicorp/go-raftchunking v0.6.3-0.20191002164813-7e9e8525653a/go.mod h1:xbXnmKqX9/+RhPkJ4zrEx4738HacP72aaUPlT2RZ4sU= | ||||
| github.com/hashicorp/go-retryablehttp v0.5.3/go.mod h1:9B5zBasrRhHXnJnui7y6sL7es7NDiJgTc6Er0maI1Xs= | ||||
| @@ -2046,8 +2047,8 @@ github.com/hashicorp/go-secure-stdlib/parseutil v0.1.7 h1:UpiO20jno/eV1eVZcxqWnU | ||||
| github.com/hashicorp/go-secure-stdlib/parseutil v0.1.7/go.mod h1:QmrqtbKuxxSWTN3ETMPuB+VtEiBJ/A9XhoYGv8E1uD8= | ||||
| github.com/hashicorp/go-secure-stdlib/password v0.1.1 h1:6JzmBqXprakgFEHwBgdchsjaA9x3GyjdI568bXKxa60= | ||||
| github.com/hashicorp/go-secure-stdlib/password v0.1.1/go.mod h1:9hH302QllNwu1o2TGYtSk8I8kTAN0ca1EHpwhm5Mmzo= | ||||
| github.com/hashicorp/go-secure-stdlib/plugincontainer v0.2.1 h1:aTW1KKDId4VQjK+zgvsu6sKlVGr17uAUAaceRwhvvoI= | ||||
| github.com/hashicorp/go-secure-stdlib/plugincontainer v0.2.1/go.mod h1:Cv387jRKKbetAp5AWK4zL7UxdeBeDTgUJOnmS4T/4I8= | ||||
| github.com/hashicorp/go-secure-stdlib/plugincontainer v0.2.2 h1:lNWQ5KVsLmzjvN11LYqaTXtMrCP7CyxfmTeR3h0l3s8= | ||||
| github.com/hashicorp/go-secure-stdlib/plugincontainer v0.2.2/go.mod h1:7xQt0+IfRmzYBLpFx+4MYfLpBdd1PT1VatGKRswf7xE= | ||||
| github.com/hashicorp/go-secure-stdlib/reloadutil v0.1.1 h1:SMGUnbpAcat8rIKHkBPjfv81yC46a8eCNZ2hsR2l1EI= | ||||
| github.com/hashicorp/go-secure-stdlib/reloadutil v0.1.1/go.mod h1:Ch/bf00Qnx77MZd49JRgHYqHQjtEmTgGU2faufpVZb0= | ||||
| github.com/hashicorp/go-secure-stdlib/strutil v0.1.1/go.mod h1:gKOamz3EwoIoJq7mlMIRBpVTAUn8qPCrEclOKKWhD3U= | ||||
|   | ||||
| @@ -24,13 +24,13 @@ require ( | ||||
| 	github.com/hashicorp/go-kms-wrapping/entropy/v2 v2.0.0 | ||||
| 	github.com/hashicorp/go-kms-wrapping/v2 v2.0.8 | ||||
| 	github.com/hashicorp/go-multierror v1.1.1 | ||||
| 	github.com/hashicorp/go-plugin v1.5.1 | ||||
| 	github.com/hashicorp/go-plugin v1.5.2 | ||||
| 	github.com/hashicorp/go-retryablehttp v0.7.1 | ||||
| 	github.com/hashicorp/go-secure-stdlib/base62 v0.1.2 | ||||
| 	github.com/hashicorp/go-secure-stdlib/mlock v0.1.2 | ||||
| 	github.com/hashicorp/go-secure-stdlib/parseutil v0.1.7 | ||||
| 	github.com/hashicorp/go-secure-stdlib/password v0.1.1 | ||||
| 	github.com/hashicorp/go-secure-stdlib/plugincontainer v0.2.1 | ||||
| 	github.com/hashicorp/go-secure-stdlib/plugincontainer v0.2.2 | ||||
| 	github.com/hashicorp/go-secure-stdlib/strutil v0.1.2 | ||||
| 	github.com/hashicorp/go-secure-stdlib/tlsutil v0.1.2 | ||||
| 	github.com/hashicorp/go-sockaddr v1.0.2 | ||||
|   | ||||
| @@ -247,8 +247,8 @@ github.com/hashicorp/go-multierror v1.0.0/go.mod h1:dHtQlpGsu+cZNNAkkCN/P3hoUDHh | ||||
| github.com/hashicorp/go-multierror v1.1.1 h1:H5DkEtf6CXdFp0N0Em5UCwQpXMWke8IA0+lD48awMYo= | ||||
| github.com/hashicorp/go-multierror v1.1.1/go.mod h1:iw975J/qwKPdAO1clOe2L8331t/9/fmwbPZ6JB6eMoM= | ||||
| github.com/hashicorp/go-plugin v1.0.1/go.mod h1:++UyYGoz3o5w9ZzAdZxtQKrWWP+iqPBn3cQptSMzBuY= | ||||
| github.com/hashicorp/go-plugin v1.5.1 h1:oGm7cWBaYIp3lJpx1RUEfLWophprE2EV/KUeqBYo+6k= | ||||
| github.com/hashicorp/go-plugin v1.5.1/go.mod h1:w1sAEES3g3PuV/RzUrgow20W2uErMly84hhD3um1WL4= | ||||
| github.com/hashicorp/go-plugin v1.5.2 h1:aWv8eimFqWlsEiMrYZdPYl+FdHaBJSN4AWwGWfT1G2Y= | ||||
| github.com/hashicorp/go-plugin v1.5.2/go.mod h1:w1sAEES3g3PuV/RzUrgow20W2uErMly84hhD3um1WL4= | ||||
| github.com/hashicorp/go-retryablehttp v0.5.3/go.mod h1:9B5zBasrRhHXnJnui7y6sL7es7NDiJgTc6Er0maI1Xs= | ||||
| github.com/hashicorp/go-retryablehttp v0.5.4/go.mod h1:9B5zBasrRhHXnJnui7y6sL7es7NDiJgTc6Er0maI1Xs= | ||||
| github.com/hashicorp/go-retryablehttp v0.7.1 h1:sUiuQAnLlbvmExtFQs72iFW/HXeUn8Z1aJLQ4LJJbTQ= | ||||
| @@ -265,8 +265,8 @@ github.com/hashicorp/go-secure-stdlib/parseutil v0.1.7 h1:UpiO20jno/eV1eVZcxqWnU | ||||
| github.com/hashicorp/go-secure-stdlib/parseutil v0.1.7/go.mod h1:QmrqtbKuxxSWTN3ETMPuB+VtEiBJ/A9XhoYGv8E1uD8= | ||||
| github.com/hashicorp/go-secure-stdlib/password v0.1.1 h1:6JzmBqXprakgFEHwBgdchsjaA9x3GyjdI568bXKxa60= | ||||
| github.com/hashicorp/go-secure-stdlib/password v0.1.1/go.mod h1:9hH302QllNwu1o2TGYtSk8I8kTAN0ca1EHpwhm5Mmzo= | ||||
| github.com/hashicorp/go-secure-stdlib/plugincontainer v0.2.1 h1:aTW1KKDId4VQjK+zgvsu6sKlVGr17uAUAaceRwhvvoI= | ||||
| github.com/hashicorp/go-secure-stdlib/plugincontainer v0.2.1/go.mod h1:Cv387jRKKbetAp5AWK4zL7UxdeBeDTgUJOnmS4T/4I8= | ||||
| github.com/hashicorp/go-secure-stdlib/plugincontainer v0.2.2 h1:lNWQ5KVsLmzjvN11LYqaTXtMrCP7CyxfmTeR3h0l3s8= | ||||
| github.com/hashicorp/go-secure-stdlib/plugincontainer v0.2.2/go.mod h1:7xQt0+IfRmzYBLpFx+4MYfLpBdd1PT1VatGKRswf7xE= | ||||
| github.com/hashicorp/go-secure-stdlib/strutil v0.1.1/go.mod h1:gKOamz3EwoIoJq7mlMIRBpVTAUn8qPCrEclOKKWhD3U= | ||||
| github.com/hashicorp/go-secure-stdlib/strutil v0.1.2 h1:kes8mmyCpxJsI7FTwtzRqEy9CdjCtrXrXGuOpxEA7Ts= | ||||
| github.com/hashicorp/go-secure-stdlib/strutil v0.1.2/go.mod h1:Gou2R9+il93BqX25LAKCLuM+y9U2T4hlwvT1yprcna4= | ||||
|   | ||||
| @@ -58,12 +58,16 @@ type runConfig struct { | ||||
| 	PluginClientConfig | ||||
| } | ||||
|  | ||||
| func (rc runConfig) mlockEnabled() bool { | ||||
| 	return rc.MLock || (rc.Wrapper != nil && rc.Wrapper.MlockEnabled()) | ||||
| } | ||||
|  | ||||
| func (rc runConfig) generateCmd(ctx context.Context) (cmd *exec.Cmd, clientTLSConfig *tls.Config, err error) { | ||||
| 	cmd = exec.Command(rc.command, rc.args...) | ||||
| 	cmd.Env = append(cmd.Env, rc.env...) | ||||
|  | ||||
| 	// Add the mlock setting to the ENV of the plugin | ||||
| 	if rc.MLock || (rc.Wrapper != nil && rc.Wrapper.MlockEnabled()) { | ||||
| 	if rc.mlockEnabled() { | ||||
| 		cmd.Env = append(cmd.Env, fmt.Sprintf("%s=%s", PluginMlockEnabled, "true")) | ||||
| 	} | ||||
| 	version, err := rc.Wrapper.VaultVersion(ctx) | ||||
| @@ -139,7 +143,8 @@ func (rc runConfig) makeConfig(ctx context.Context) (*plugin.ClientConfig, error | ||||
| 		clientConfig.SkipHostEnv = true | ||||
| 		clientConfig.RunnerFunc = containerCfg.NewContainerRunner | ||||
| 		clientConfig.UnixSocketConfig = &plugin.UnixSocketConfig{ | ||||
| 			Group: strconv.Itoa(containerCfg.GroupAdd), | ||||
| 			Group:   strconv.Itoa(containerCfg.GroupAdd), | ||||
| 			TempDir: os.Getenv("VAULT_PLUGIN_TMPDIR"), | ||||
| 		} | ||||
| 	} | ||||
| 	return clientConfig, nil | ||||
| @@ -155,9 +160,10 @@ func (rc runConfig) containerConfig(ctx context.Context, env []string) (*pluginc | ||||
| 		Tag:    rc.imageTag, | ||||
| 		SHA256: fmt.Sprintf("%x", rc.sha256), | ||||
|  | ||||
| 		Env:      env, | ||||
| 		GroupAdd: os.Getgid(), | ||||
| 		Runtime:  consts.DefaultContainerPluginOCIRuntime, | ||||
| 		Env:        env, | ||||
| 		GroupAdd:   os.Getgid(), | ||||
| 		Runtime:    consts.DefaultContainerPluginOCIRuntime, | ||||
| 		CapIPCLock: rc.mlockEnabled(), | ||||
| 		Labels: map[string]string{ | ||||
| 			labelVaultPID:           strconv.Itoa(os.Getpid()), | ||||
| 			labelVaultClusterID:     clusterID, | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Tom Proctor
					Tom Proctor