-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for a policy resource to Teleport (#17220)
* add workings for policy resource * add grpc defs for create/get policy * policy resource plumbing * fix some bugs & add tctl get command * add listing code * use a custom api instead of listresources * rename ListPolicies to GetPolicies * update allow/deny/options to be a map of scopes instead * keep option a nonmap * trim policy def * touchups * add rbac checks * revert e ref * rename
- Loading branch information
Showing
16 changed files
with
3,646 additions
and
1,880 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
Large diffs are not rendered by default.
Oops, something went wrong.
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,118 @@ | ||
/* | ||
Copyright 2022 Gravitational, Inc. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package types | ||
|
||
import ( | ||
"time" | ||
|
||
"github.com/gravitational/trace" | ||
) | ||
|
||
// AccessPolicyV1 is a predicate policy used for RBAC, similar to rule but uses predicate language. | ||
type Policy interface { | ||
// Resource provides common resource properties | ||
Resource | ||
// GetAllow returns a list of allow expressions grouped by scope. | ||
GetAllow() map[string]string | ||
// GetDeny returns a list of deny expressions grouped by scope. | ||
GetDeny() map[string]string | ||
} | ||
|
||
// GetVersion returns resource version | ||
func (c *AccessPolicyV1) GetVersion() string { | ||
return c.Version | ||
} | ||
|
||
// GetKind returns resource kind | ||
func (c *AccessPolicyV1) GetKind() string { | ||
return c.Kind | ||
} | ||
|
||
// GetSubKind returns resource sub kind | ||
func (c *AccessPolicyV1) GetSubKind() string { | ||
return c.SubKind | ||
} | ||
|
||
// SetSubKind sets resource subkind | ||
func (c *AccessPolicyV1) SetSubKind(s string) { | ||
c.SubKind = s | ||
} | ||
|
||
// GetResourceID returns resource ID | ||
func (c *AccessPolicyV1) GetResourceID() int64 { | ||
return c.Metadata.ID | ||
} | ||
|
||
// SetResourceID sets resource ID | ||
func (c *AccessPolicyV1) SetResourceID(id int64) { | ||
c.Metadata.ID = id | ||
} | ||
|
||
// setStaticFields sets static resource header and metadata fields. | ||
func (c *AccessPolicyV1) setStaticFields() { | ||
c.Kind = KindAccessPolicy | ||
c.Version = V1 | ||
} | ||
|
||
// CheckAndSetDefaults checks and sets default values | ||
func (c *AccessPolicyV1) CheckAndSetDefaults() error { | ||
c.setStaticFields() | ||
if err := c.Metadata.CheckAndSetDefaults(); err != nil { | ||
return trace.Wrap(err) | ||
} | ||
return nil | ||
} | ||
|
||
// GetMetadata returns object metadata | ||
func (c *AccessPolicyV1) GetMetadata() Metadata { | ||
return c.Metadata | ||
} | ||
|
||
// SetMetadata sets remote cluster metatada | ||
func (c *AccessPolicyV1) SetMetadata(meta Metadata) { | ||
c.Metadata = meta | ||
} | ||
|
||
// SetExpiry sets expiry time for the object | ||
func (c *AccessPolicyV1) SetExpiry(expires time.Time) { | ||
c.Metadata.SetExpiry(expires) | ||
} | ||
|
||
// Expiry returns object expiry setting | ||
func (c *AccessPolicyV1) Expiry() time.Time { | ||
return c.Metadata.Expiry() | ||
} | ||
|
||
// GetName returns the name of the RemoteCluster. | ||
func (c *AccessPolicyV1) GetName() string { | ||
return c.Metadata.Name | ||
} | ||
|
||
// SetName sets the name of the RemoteCluster. | ||
func (c *AccessPolicyV1) SetName(e string) { | ||
c.Metadata.Name = e | ||
} | ||
|
||
// GetAllow returns a list of allow expressions grouped by scope. | ||
func (c *AccessPolicyV1) GetAllow() map[string]string { | ||
return c.Spec.Allow | ||
} | ||
|
||
// GetDeny returns a list of deny expressions grouped by scope. | ||
func (c *AccessPolicyV1) GetDeny() map[string]string { | ||
return c.Spec.Deny | ||
} |
Oops, something went wrong.