Creating an Istio Authorization Policy dinamically #5301
gaetanodigenio
started this conversation in
General
Replies: 2 comments 12 replies
-
@gaetanodigenio : Could you please check if this works? if(!fromNamespaces.isEmpty()){
for (String fromNamespace: fromNamespaces){
builder.editSpec()
.addToRules(new RuleBuilder()
.withFrom(new RuleFromBuilder().withSource(new SourceBuilder().withNamespaces(fromNamespace).build()).build())
.withTo(new RuleToBuilder().withOperation(new OperationBuilder().withMethods(method).build()).build())
.build())
.endSpec();
}
} |
Beta Was this translation helpful? Give feedback.
8 replies
-
I also have a problem adding the "action" field. It doesn't add anything in the final policy, the action field doesn't exists. System.out.println("Creating a AuthorizationPolicy entry");
AuthorizationPolicyBuilder builder = new AuthorizationPolicyBuilder()
.withNewMetadata()
.withName(policyName)
.endMetadata()
.withNewSpec()
.withSelector(new WorkloadSelectorBuilder().withMatchLabels(Collections.singletonMap("app", appLabel)).build())
.withAction(AuthorizationPolicyAction.ALLOW)
.endSpec(); Maybe I should add the action field later? How can I do that? |
Beta Was this translation helpful? Give feedback.
4 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi everyone,
I wanted to create an Istio policy dynamically.
I've seen that a policy can be created most statically in this way for example:
and then I can do:
Assuming that all the parameters are given in input by a specific user.
I wanted to create now the same policy, but actually adding the rules only if there are any.
If an user sends some "fromNamespaces" in an array since they can be multiple, I want to iterate for each element of the array and create the rule to add to the rest of the policy later.
Same apply for other "from" parameters and also the "to" parameters.
Something like this:
How can this be achieved? I hope it's clear what I want to do.
Thanks in advance
Beta Was this translation helpful? Give feedback.
All reactions