Skip to content

Conversation

rshriram
Copy link
Member

@rshriram rshriram commented Jun 4, 2020

Enhancing from the existing . and * to allow users to export to specific set of namespaces.

[ ] Configuration Infrastructure
[ ] Docs
[ ] Installation
[x ] Networking
[ ] Performance and Scalability
[ ] Policies and Telemetry
[ ] Security
[ ] Test and Release
[ ] User Experience
[ ] Developer Infrastructure

Signed-off-by: Shriram Rajagopalan <rshriram@tetrate.io>
@rshriram rshriram requested review from a team as code owners June 4, 2020 20:21
@istio-testing istio-testing added the do-not-merge/work-in-progress Block merging of a PR because it isn't ready yet. label Jun 4, 2020
@googlebot googlebot added the cla: yes Set by the Google CLA bot to indicate the author of a PR has signed the Google CLA. label Jun 4, 2020
@istio-testing istio-testing added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Jun 4, 2020
@rshriram
Copy link
Member Author

rshriram commented Jun 5, 2020

/hold
The logic isn’t quite right for destination rules

@istio-testing istio-testing added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Jun 5, 2020
@rshriram rshriram changed the title [WIP] support exportTo specific namespaces support exportTo specific namespaces Jun 5, 2020
@istio-testing istio-testing removed the do-not-merge/work-in-progress Block merging of a PR because it isn't ready yet. label Jun 5, 2020
@rshriram
Copy link
Member Author

rshriram commented Jun 5, 2020

/hold cancel

@rshriram
Copy link
Member Author

rshriram commented Jun 5, 2020

@istio/wg-networking-maintainers-pilot this is now ready for review

@rshriram
Copy link
Member Author

rshriram commented Jun 5, 2020

/test integ-security-k8s-tests_istio

@@ -71,10 +71,14 @@ type PushContext struct {
// Service related
// TODO: move to a sub struct

// privateServices are reachable within the same namespace.
// privateServices are reachable within the same namespace, with exportTo .
Copy link
Contributor

@ramaraochavali ramaraochavali Jun 6, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: can you please put . -> "." so that we do not get confused with end of sentence?

Copy link
Contributor

@ramaraochavali ramaraochavali left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, couple minor nits

// check the target service's namespace for public rules
if svcNs != "" && ps.namespaceExportedDestRules[svcNs] != nil {
// check the target service's namespace for exported rules
if svcNs != "" && ps.exportedDestRulesByNamespace[svcNs] != nil {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We store destination rule by the ns it resides, not by function scope. So it seems we are missing check for its function scope in the first step in L721.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what do you mean by function scope? The algorithm is look in proxy's namespace first (doesn't matter if the service does not belong ot the proxy's namespace. if there is a dest rule in proxy's namespace for that service, pick it up first). Then look in the target service's namespace for public rules or rules that are explicitly exported to the proxy's namespace (in either case, this dest rule is "visible" to the proxy's namespace).

And then finally look in config root namespace.

}
} else if len(rule.ExportTo) == 1 && exportToMap[visibility.Private] {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: concate with if condition

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what do you mean ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: i mean the if else conditions can be merged

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@@ -69,6 +85,11 @@ func mergeVirtualServicesIfNeeded(vServices []Config) (out []Config) {
// delegate not found, ignore only the current HTTP route
continue
}
// make sure that the delegate is visible to root virtual service's namespace
exportTo := delegatesExportToMap[key(route.Delegate.Name, route.Delegate.Namespace)]
if !exportTo[visibility.Public] && !exportTo[visibility.Instance(root.Namespace)] {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a debug log here

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

}
} else {
// if this is a serviceEntry, allow ~ in exportTo
if isServiceEntry && visibility.Instance(e) == visibility.None {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why make SE unique here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure if we will have a definitive use case for this but if we ever do, the only config that can support ~ is the serviceEntry - think of the scenario where you have a cronjob with some dummy service assigned to it, and you want to make sure no one can talk to the cronjob.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then the question comes, if it is not intended to be accessed, why even create a SE/service for it?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the proxies that implement that service - so that the GetProxyServiceInstances() doesn't return empty. Also, if a service is present, then metrics will be present. E.g., a cron job that calls a bunch of internal APIs every 10s..

rshriram added 2 commits June 8, 2020 14:03
Signed-off-by: Shriram Rajagopalan <rshriram@tetrate.io>
default:
return fmt.Errorf("only . or * is allowed in the exportTo in the current release")
if !labels.IsDNS1123Label(string(v)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, this is not right. The allowed length is 63 here. But in k8s the allowed name length is <= 253

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have found many misuse of IsDNS1123Label in the whole repo

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure kubernetes namespaces can be >63 characters? If the name is 253 characters, then no one can create a service inside a namespace as the total DNS name length will be >255 characters.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right, i am looking at something wrong

@nrjpoddar
Copy link
Member

@rshriram is there any Github issue for this? There's #24019 which is only partially solves by this.

@rshriram
Copy link
Member Author

rshriram commented Jun 9, 2020

issue for what? exportTo to specific namespaces is part of the networking items to tackle for 1.7 (marked as P1 IIRC).

rshriram added 3 commits June 9, 2020 10:17
Signed-off-by: Shriram Rajagopalan <rshriram@tetrate.io>
Signed-off-by: Shriram Rajagopalan <rshriram@tetrate.io>
@esnible
Copy link
Contributor

esnible commented Jun 9, 2020

I will need to extend the istioctl analyze code to recognize this feature.

Do you have yaml files making use of this that you use for tests or as samples? If so I would like to use them to write analysis test cases. (It not I will create my own.)

@rshriram
Copy link
Member Author

rshriram commented Jun 9, 2020

@esnible there is no syntactic change. Here is one sample YAML

apiVersion: networking.istio.io/v1beta1
kind: VirtualService
metadata:
 name: foo
 namespace: ns1
spec:
   hosts:
   - bookinfo.com
   exportTo:
    - '.'
    - 'ns2'
    - 'ns3'
    http:
    ...

@rshriram
Copy link
Member Author

rshriram commented Jun 9, 2020

also, cc @Stono - this is something you asked for a long time ago :).

@esnible
Copy link
Contributor

esnible commented Jun 10, 2020

@rshriram

We have an analyzer that verifies that every VirtualService.http.route.destination.subset is defined by a DestinationRule.subsets[*].name. With this change it will be possible to create a VirtualService that is valid in some namespaces but not in others.

As a user, if I made the mistake below, I would want a hint from analyze. Something like Info [IST0101] (VirtualService reviews.default) Referenced host+subset defined by DestinationRule reviews.default with narrower exportTo scope.

apiVersion: networking.istio.io/v1alpha3
kind: DestinationRule
metadata:
  name: reviews
spec:
  host: reviews
  exportTo: ["istio-system"] # RESTRICT VISIBILITY
  subsets:
  - name: v1
    labels:
      version: v1
---
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
  name: reviews
spec:
  hosts:
  - reviews
  http:
  - route:
    - destination:
        host: reviews
        subset: v1

Copy link
Member

@hzxuzhonghu hzxuzhonghu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The istioctl part can be done in another pr, this one is big.

@Stono
Copy link
Contributor

Stono commented Jun 10, 2020

Wooooo cool

nschhina pushed a commit to nschhina/istio that referenced this pull request Jun 18, 2020
* support exportTo specific namespaces

Signed-off-by: Shriram Rajagopalan <rshriram@tetrate.io>

* tests and bug fixes

Signed-off-by: Shriram Rajagopalan <rshriram@tetrate.io>

* enclose dot in quotes to differentiate from full stop

Signed-off-by: Shriram Rajagopalan <rshriram@tetrate.io>

* nits

Signed-off-by: Shriram Rajagopalan <rshriram@tetrate.io>

* update merge logic comments

Signed-off-by: Shriram Rajagopalan <rshriram@tetrate.io>

* merge if

Signed-off-by: Shriram Rajagopalan <rshriram@tetrate.io>
@hzxuzhonghu hzxuzhonghu deleted the exportto_ns branch June 19, 2020 01:56
istio-testing pushed a commit to istio/api that referenced this pull request Sep 24, 2020
It is now possible to use exportTo to export to specific
namespaces. Was fixed in istio/istio#24443
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes Set by the Google CLA bot to indicate the author of a PR has signed the Google CLA. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants