Skip to content

Commit c759e92

Browse files
Google APIscopybara-github
authored andcommitted
feat: Add managed constraints new fields (e.g. parameter)
docs: updated comments PiperOrigin-RevId: 748671918
1 parent d4584b3 commit c759e92

3 files changed

Lines changed: 174 additions & 29 deletions

File tree

google/cloud/orgpolicy/v2/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ proto_library(
3232
"//google/type:expr_proto",
3333
"@com_google_protobuf//:empty_proto",
3434
"@com_google_protobuf//:field_mask_proto",
35+
"@com_google_protobuf//:struct_proto",
3536
"@com_google_protobuf//:timestamp_proto",
3637
],
3738
)

google/cloud/orgpolicy/v2/constraint.proto

Lines changed: 151 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package google.cloud.orgpolicy.v2;
1818

1919
import "google/api/field_behavior.proto";
2020
import "google/api/resource.proto";
21+
import "google/protobuf/struct.proto";
2122
import "google/protobuf/timestamp.proto";
2223

2324
option csharp_namespace = "Google.Cloud.OrgPolicy.V2";
@@ -36,8 +37,8 @@ option ruby_package = "Google::Cloud::OrgPolicy::V2";
3637
// organization by setting a policy that includes constraints at different
3738
// locations in the organization's resource hierarchy. Policies are inherited
3839
// down the resource hierarchy from higher levels, but can also be overridden.
39-
// For details about the inheritance rules please read about
40-
// [`policies`][google.cloud.OrgPolicy.v2.Policy].
40+
// For details about the inheritance rules, see
41+
// [`Policy`][google.cloud.orgpolicy.v2.Policy].
4142
//
4243
// Constraints have a default behavior determined by the `constraint_default`
4344
// field, which is the enforcement behavior that is used in the absence of a
@@ -56,7 +57,7 @@ message Constraint {
5657
// Immutable after creation.
5758
enum ConstraintDefault {
5859
// This is only used for distinguishing unset values and should never be
59-
// used.
60+
// used. Results in an error.
6061
CONSTRAINT_DEFAULT_UNSPECIFIED = 0;
6162

6263
// Indicate that all values are allowed for list constraints.
@@ -68,8 +69,9 @@ message Constraint {
6869
DENY = 2;
6970
}
7071

71-
// A constraint that allows or disallows a list of string values, which are
72-
// configured by an Organization Policy administrator with a policy.
72+
// A constraint type that allows or disallows a list of string values, which
73+
// are configured in the
74+
// [`PolicyRule`][google.cloud.orgpolicy.v2.PolicySpec.PolicyRule].
7375
message ListConstraint {
7476
// Indicates whether values grouped into categories can be used in
7577
// `Policy.allowed_values` and `Policy.denied_values`. For example,
@@ -83,12 +85,131 @@ message Constraint {
8385
bool supports_under = 2;
8486
}
8587

86-
// A constraint that is either enforced or not.
88+
// Custom constraint definition. Defines this as a managed constraint.
89+
message CustomConstraintDefinition {
90+
// The operation for which this constraint will be applied. To apply this
91+
// constraint only when creating new resources, the `method_types` should be
92+
// `CREATE` only. To apply this constraint when creating or deleting
93+
// resources, the `method_types` should be `CREATE` and `DELETE`.
94+
//
95+
// `UPDATE`-only custom constraints are not supported. Use `CREATE` or
96+
// `CREATE, UPDATE`.
97+
enum MethodType {
98+
// This is only used for distinguishing unset values and should never be
99+
// used. Results in an error.
100+
METHOD_TYPE_UNSPECIFIED = 0;
101+
102+
// Constraint applied when creating the resource.
103+
CREATE = 1;
104+
105+
// Constraint applied when updating the resource.
106+
UPDATE = 2;
107+
108+
// Constraint applied when deleting the resource.
109+
// Not currently supported.
110+
DELETE = 3;
111+
112+
// Constraint applied when removing an IAM grant.
113+
REMOVE_GRANT = 4;
114+
115+
// Constraint applied when enforcing forced tagging.
116+
GOVERN_TAGS = 5;
117+
}
118+
119+
// Allow or deny type.
120+
enum ActionType {
121+
// This is only used for distinguishing unset values and should never be
122+
// used. Results in an error.
123+
ACTION_TYPE_UNSPECIFIED = 0;
124+
125+
// Allowed action type.
126+
ALLOW = 1;
127+
128+
// Deny action type.
129+
DENY = 2;
130+
}
131+
132+
// Defines a parameter structure.
133+
message Parameter {
134+
// All valid types of parameter.
135+
enum Type {
136+
// This is only used for distinguishing unset values and should never be
137+
// used. Results in an error.
138+
TYPE_UNSPECIFIED = 0;
139+
140+
// List parameter type.
141+
LIST = 1;
142+
143+
// String parameter type.
144+
STRING = 2;
145+
146+
// Boolean parameter type.
147+
BOOLEAN = 3;
148+
}
149+
150+
// Defines Metadata structure.
151+
message Metadata {
152+
// Detailed description of what this `parameter` is and use of it.
153+
// Mutable.
154+
string description = 1;
155+
}
156+
157+
// Type of the parameter.
158+
Type type = 1;
159+
160+
// Sets the value of the parameter in an assignment if no value is given.
161+
google.protobuf.Value default_value = 2;
162+
163+
// Provides a CEL expression to specify the acceptable parameter values
164+
// during assignment.
165+
// For example, parameterName in ("parameterValue1", "parameterValue2")
166+
string valid_values_expr = 3;
167+
168+
// Defines subproperties primarily used by the UI to display user-friendly
169+
// information.
170+
Metadata metadata = 4;
171+
172+
// Determines the parameter's value structure.
173+
// For example, `LIST<STRING>` can be specified by defining `type: LIST`,
174+
// and `item: STRING`.
175+
Type item = 5;
176+
}
177+
178+
// The resource instance type on which this policy applies. Format will be
179+
// of the form : `<service name>/<type>` Example:
180+
//
181+
// * `compute.googleapis.com/Instance`.
182+
repeated string resource_types = 1;
183+
184+
// All the operations being applied for this constraint.
185+
repeated MethodType method_types = 2;
186+
187+
// Org policy condition/expression. For example:
188+
// `resource.instanceName.matches("[production|test]_.*_(\d)+")` or,
189+
// `resource.management.auto_upgrade == true`
190+
//
191+
// The max length of the condition is 1000 characters.
192+
string condition = 3;
193+
194+
// Allow or deny type.
195+
ActionType action_type = 4;
196+
197+
// Stores the structure of
198+
// [`Parameters`][google.cloud.orgpolicy.v2.Constraint.CustomConstraintDefinition.Parameter]
199+
// used by the constraint condition. The key of `map` represents the name of
200+
// the parameter.
201+
map<string, Parameter> parameters = 5;
202+
}
203+
204+
// A constraint type is enforced or not enforced, which is configured in the
205+
// [`PolicyRule`][google.cloud.orgpolicy.v2.PolicySpec.PolicyRule].
87206
//
88-
// For example, a constraint `constraints/compute.disableSerialPortAccess`.
89-
// If it is enforced on a VM instance, serial port connections will not be
90-
// opened to that instance.
91-
message BooleanConstraint {}
207+
// If `customConstraintDefinition` is defined, this constraint is a managed
208+
// constraint.
209+
message BooleanConstraint {
210+
// Custom constraint definition. Defines this as a managed constraint.
211+
CustomConstraintDefinition custom_constraint_definition = 1;
212+
}
92213

93214
// Immutable. The resource name of the constraint. Must be in one of
94215
// the following forms:
@@ -118,15 +239,22 @@ message Constraint {
118239
//
119240
// Immutable after creation.
120241
oneof constraint_type {
121-
// Defines this constraint as being a ListConstraint.
242+
// Defines this constraint as being a list constraint.
122243
ListConstraint list_constraint = 5;
123244

124-
// Defines this constraint as being a BooleanConstraint.
245+
// Defines this constraint as being a boolean constraint.
125246
BooleanConstraint boolean_constraint = 6;
126247
}
127248

128249
// Shows if dry run is supported for this constraint or not.
129250
bool supports_dry_run = 7;
251+
252+
// Managed constraint and canned constraint sometimes can have
253+
// equivalents. This field is used to store the equivalent constraint name.
254+
string equivalent_constraint = 8;
255+
256+
// Shows if simulation is supported for this constraint or not.
257+
bool supports_simulation = 9;
130258
}
131259

132260
// A custom constraint defined by customers which can *only* be applied to the
@@ -142,14 +270,15 @@ message CustomConstraint {
142270
};
143271

144272
// The operation for which this constraint will be applied. To apply this
145-
// constraint only when creating new VMs, the `method_types` should be
273+
// constraint only when creating new resources, the `method_types` should be
146274
// `CREATE` only. To apply this constraint when creating or deleting
147-
// VMs, the `method_types` should be `CREATE` and `DELETE`.
275+
// resources, the `method_types` should be `CREATE` and `DELETE`.
148276
//
149277
// `UPDATE` only custom constraints are not supported. Use `CREATE` or
150278
// `CREATE, UPDATE`.
151279
enum MethodType {
152-
// Unspecified. Results in an error.
280+
// This is only used for distinguishing unset values and should never be
281+
// used. Results in an error.
153282
METHOD_TYPE_UNSPECIFIED = 0;
154283

155284
// Constraint applied when creating the resource.
@@ -159,7 +288,7 @@ message CustomConstraint {
159288
UPDATE = 2;
160289

161290
// Constraint applied when deleting the resource.
162-
// Not supported yet.
291+
// Not currently supported.
163292
DELETE = 3;
164293

165294
// Constraint applied when removing an IAM grant.
@@ -171,7 +300,8 @@ message CustomConstraint {
171300

172301
// Allow or deny type.
173302
enum ActionType {
174-
// Unspecified. Results in an error.
303+
// This is only used for distinguishing unset values and should never be
304+
// used. Results in an error.
175305
ACTION_TYPE_UNSPECIFIED = 0;
176306

177307
// Allowed action type.
@@ -193,15 +323,16 @@ message CustomConstraint {
193323
string name = 1 [(google.api.field_behavior) = IMMUTABLE];
194324

195325
// Immutable. The resource instance type on which this policy applies. Format
196-
// will be of the form : `<canonical service name>/<type>` Example:
326+
// will be of the form : `<service name>/<type>` Example:
197327
//
198328
// * `compute.googleapis.com/Instance`.
199329
repeated string resource_types = 2 [(google.api.field_behavior) = IMMUTABLE];
200330

201331
// All the operations being applied for this constraint.
202332
repeated MethodType method_types = 3;
203333

204-
// Org policy condition/expression. For example:
334+
// A Common Expression Language (CEL) condition which is used in the
335+
// evaluation of the constraint. For example:
205336
// `resource.instanceName.matches("[production|test]_.*_(\d)+")` or,
206337
// `resource.management.auto_upgrade == true`
207338
//
@@ -221,7 +352,7 @@ message CustomConstraint {
221352

222353
// Output only. The last time this custom constraint was updated. This
223354
// represents the last time that the `CreateCustomConstraint` or
224-
// `UpdateCustomConstraint` RPC was called
355+
// `UpdateCustomConstraint` methods were called.
225356
google.protobuf.Timestamp update_time = 8
226357
[(google.api.field_behavior) = OUTPUT_ONLY];
227358
}

google/cloud/orgpolicy/v2/orgpolicy.proto

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import "google/api/resource.proto";
2323
import "google/cloud/orgpolicy/v2/constraint.proto";
2424
import "google/protobuf/empty.proto";
2525
import "google/protobuf/field_mask.proto";
26+
import "google/protobuf/struct.proto";
2627
import "google/protobuf/timestamp.proto";
2728
import "google/type/expr.proto";
2829

@@ -204,10 +205,10 @@ service OrgPolicy {
204205
option (google.api.method_signature) = "custom_constraint";
205206
}
206207

207-
// Gets a custom constraint.
208+
// Gets a custom or managed constraint.
208209
//
209210
// Returns a `google.rpc.Status` with `google.rpc.Code.NOT_FOUND` if the
210-
// custom constraint does not exist.
211+
// custom or managed constraint does not exist.
211212
rpc GetCustomConstraint(GetCustomConstraintRequest)
212213
returns (CustomConstraint) {
213214
option (google.api.http) = {
@@ -264,7 +265,7 @@ message Policy {
264265
// the equivalent project number.
265266
string name = 1 [(google.api.field_behavior) = IMMUTABLE];
266267

267-
// Basic information about the Organization Policy.
268+
// Basic information about the organization policy.
268269
PolicySpec spec = 2;
269270

270271
// Deprecated.
@@ -283,7 +284,7 @@ message Policy {
283284
}
284285

285286
// Similar to PolicySpec but with an extra 'launch' field for launch reference.
286-
// The PolicySpec here is specific for dry-run/darklaunch.
287+
// The PolicySpec here is specific for dry-run.
287288
message AlternatePolicySpec {
288289
// Reference to the launch that will be used while audit logging and to
289290
// control the launch.
@@ -356,6 +357,17 @@ message PolicySpec {
356357
// 'prod')". or "resource.matchTagId('tagKeys/123',
357358
// 'tagValues/456')".
358359
google.type.Expr condition = 5;
360+
361+
// Optional. Required for managed constraints if parameters are defined.
362+
// Passes parameter values when policy enforcement is enabled. Ensure that
363+
// parameter value types match those defined in the constraint definition.
364+
// For example:
365+
// {
366+
// "allowedLocations" : ["us-east1", "us-west1"],
367+
// "allowAll" : true
368+
// }
369+
google.protobuf.Struct parameters = 6
370+
[(google.api.field_behavior) = OPTIONAL];
359371
}
360372

361373
// An opaque tag indicating the current version of the policySpec, used for
@@ -580,8 +592,8 @@ message CreateCustomConstraintRequest {
580592
// The request sent to the [GetCustomConstraint]
581593
// [google.cloud.orgpolicy.v2.OrgPolicy.GetCustomConstraint] method.
582594
message GetCustomConstraintRequest {
583-
// Required. Resource name of the custom constraint. See the custom constraint
584-
// entry for naming requirements.
595+
// Required. Resource name of the custom or managed constraint. See the custom
596+
// constraint entry for naming requirements.
585597
string name = 1 [
586598
(google.api.field_behavior) = REQUIRED,
587599
(google.api.resource_reference) = {
@@ -617,10 +629,11 @@ message ListCustomConstraintsRequest {
617629

618630
// The response returned from the [ListCustomConstraints]
619631
// [google.cloud.orgpolicy.v2.OrgPolicy.ListCustomConstraints] method. It will
620-
// be empty if no custom constraints are set on the organization resource.
632+
// be empty if no custom or managed constraints are set on the organization
633+
// resource.
621634
message ListCustomConstraintsResponse {
622-
// All custom constraints that exist on the organization resource. It will be
623-
// empty if no custom constraints are set.
635+
// All custom and managed constraints that exist on the organization resource.
636+
// It will be empty if no custom constraints are set.
624637
repeated CustomConstraint custom_constraints = 1;
625638

626639
// Page token used to retrieve the next page. This is currently not used, but

0 commit comments

Comments
 (0)