-
Notifications
You must be signed in to change notification settings - Fork 259
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
securitypolicy: add security policy enforcer registration and defaults (
#1476) * Stub out Rego policy enforcer and hide it behind a build tag. Add enforcer registration logic and support for default enforcer. The host can request which security policy enforcer to use with supplied policy, if none supplied, GCS code tries to make a "guess" as to which enforcer should be used: "allow all" or "default". Default enforcer is set to `StandardSecurityPolicyEnforcer` unless GCS is built with "rego" tag present. In that case, the default enforcer will be set to `RegoEnforcer`. New annotation has been added that allows callers to pick which enforcer to use, e.g. ```pod.json { ... "annotations": { "io.microsoft.virtualmachine.lcow.enforcer": "rego" }, ... } ``` Signed-off-by: Maksim An <maksiman@microsoft.com>
- Loading branch information
Showing
13 changed files
with
174 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
//go:build linux && rego | ||
// +build linux,rego | ||
|
||
package securitypolicy | ||
|
||
import ( | ||
"errors" | ||
|
||
oci "github.com/opencontainers/runtime-spec/specs-go" | ||
) | ||
|
||
const regoEnforcer = "rego" | ||
|
||
func init() { | ||
registeredEnforcers[regoEnforcer] = createRegoEnforcer | ||
// Overriding the value inside init guarantees that this assignment happens | ||
// after the variable has been initialized in securitypolicy.go and there | ||
// are no race conditions. When multiple init functions are defined in a | ||
// single package, the order of their execution is determined by the | ||
// filename. | ||
defaultEnforcer = regoEnforcer | ||
} | ||
|
||
// RegoEnforcer is a stub implementation of a security policy, which will be | ||
// based on [Rego] policy language. The detailed implementation will be | ||
// introduced in the subsequent PRs and documentation updated accordingly. | ||
// | ||
// [Rego]: https://www.openpolicyagent.org/docs/latest/policy-language/ | ||
type RegoEnforcer struct{} | ||
|
||
var ( | ||
_ SecurityPolicyEnforcer = (*RegoEnforcer)(nil) | ||
ErrNotImplemented = errors.New("not implemented") | ||
) | ||
|
||
func createRegoEnforcer(_ SecurityPolicyState, _, _ []oci.Mount) (SecurityPolicyEnforcer, error) { | ||
return &RegoEnforcer{}, nil | ||
} | ||
|
||
func (RegoEnforcer) EnforceDeviceMountPolicy(_, _ string) error { | ||
return ErrNotImplemented | ||
} | ||
|
||
func (RegoEnforcer) EnforceDeviceUnmountPolicy(_ string) error { | ||
return ErrNotImplemented | ||
} | ||
|
||
func (RegoEnforcer) EnforceOverlayMountPolicy(_ string, _ []string) error { | ||
return ErrNotImplemented | ||
} | ||
|
||
func (RegoEnforcer) EnforceCreateContainerPolicy(_ string, _, _ []string, _ string) error { | ||
return ErrNotImplemented | ||
} | ||
|
||
func (RegoEnforcer) EnforceWaitMountPointsPolicy(_ string, _ *oci.Spec) error { | ||
return ErrNotImplemented | ||
} | ||
|
||
func (RegoEnforcer) EnforceMountPolicy(_, _ string, _ *oci.Spec) error { | ||
return ErrNotImplemented | ||
} | ||
|
||
func (RegoEnforcer) ExtendDefaultMounts(_ []oci.Mount) error { | ||
return ErrNotImplemented | ||
} | ||
|
||
func (RegoEnforcer) EncodedSecurityPolicy() string { | ||
return "" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters