Skip to content

Article: Authenticating microservices requests in Kubernetes #327

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 50 commits into
base: master
Choose a base branch
from

Conversation

amitsaha
Copy link
Collaborator

@amitsaha amitsaha commented Nov 11, 2020

Now, go back to the previous terminal window with the API service and issue the same request again:

```terminal|command=1|title=bash
curl <insert URL from above>
Copy link
Contributor

Choose a reason for hiding this comment

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

If we don't amend the Service earlier, this should container an example of the output above instead of <>

You can issue a request with:

```terminal|command=1|title=bash
curl <insert URL from above>
Copy link
Contributor

Choose a reason for hiding this comment

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

If we don't amend the Service earlier, this should container an example of the output above instead of <>

@amitsaha
Copy link
Collaborator Author

@danielepolencic it looks like you have made most of the changes you were thinking of - I made a few more edits.

I am not sure why the article isn't showing up in the preview.

```

In this case, the token you will use to authenticate to the API server as well as verify the status
of is the same. Thus, the curl command to run in the pod shell session is:
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this sentence necessary? When is the token not the same?
I'm a bit confused since the assumption is that I need only 1 token.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@danielepolencic Consider the the 2nd demo - where the secret store is going to verify whether the token presented to it via the calling service (API) is legit or not. The secret store uses its own SA token to authenticate itself to the API when it makes a TokenReview request to validate the API token. In that case, the token being verified is different from the token being used to authenticate itself.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm tempted to explain that when we get to it.
It's easier if we make the content progressively more complex than presenting all the complexity upfront.
Thoughts?


You can solve the above problems by implementing solutions such as mutual TLS or using a JWT based solution with a central authority server.

However, in Kubernetes, you can use the service account token volume projection feature to create time-bound and audience-specific service account tokens which do not persist in the cluster store.
Copy link
Contributor

Choose a reason for hiding this comment

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

which do not persist in the cluster store

Not sure what this means. the two features listed do not imply that the data is not stored?


The Kubernetes API server performs the role of the central authority server and you don't have to worry about any of the internal details of expiring the tokens and more.

This feature was introduced in Kubernetes 1.12 and gained further improvements in 1.13 and provides a more secure alternative to workload-specific service accounts.
Copy link
Contributor

Choose a reason for hiding this comment

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

Missing link to verify the claim. Official link to the doc would be nice.


```go
result, err := clientset.AuthenticationV1().TokenReviews().Create(ctx, &tr, metav1.CreateOptions{})
```
Copy link
Contributor

Choose a reason for hiding this comment

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

You broke the code line-by-line.
The idea is good, but I think it could be refactored to provide more context.
Keep the line by line, but should the snippet truncated in full.
Then use highlight in the code snippet to highlight specific parts.
In that way you offer context, but you can explain individual parts.

kube-system system:persistent-volume-provisioner 2020-11-20T22:04:53Z
```

In the following example, you will use the `system:auth-delegator` role which has all the permission you need to call the Token Review API.
Copy link
Contributor

Choose a reason for hiding this comment

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

There's no system:auth-delegator when I list the roles. Not even in the table above. How did you create that?

@danielepolencic
Copy link
Contributor

danielepolencic commented Nov 21, 2020

A few general notes:

  • there are three components: API, data store and secret store. However, the tutorial covers only 2: API + secret store. I think we should remove the data store. Or (even better), we could remove the data store and rename the secret store to data store. At the moment there's a lot of "secret" in the article. Sometimes it's the secret store, sometimes it's kubernetes. If we remove the word secret from the apps, there's no doubt about what secrets we are talking about.
  • ca.crt, system:auth-delegator need clarifications. I don't have those in my minikube.
  • We ask to open 3 terminal windows, but we do nothing with them. I think from the current copy, two are enough.
  • I'd like to figure out why the "projected volume" is called as such.
  • I will add some background (and picture) about Role/ClusterRole.
  • ClusterRoleBindings use an old API which displays an error in 1.19
  • Authentication is not authorization, but the article seems to use the terms interchagably. I think the TokenReview API is authentication, but when you use to verify the audience you are implementing custom authorization.


You're issueing a request using your own account (cluster admin) and validating the token for a Service account.

It's easier to explain, and we skip the part where we connect to the API. The same part is skipped in the Go client too (it's part of the SDK).
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Nice find! I think i see your point here - not showing you to access the API directly.

How about we use kubectl to show the token review operation but use the token for the service token instead via the --token argument?

In addition can we still keep the curl bit?

Copy link
Contributor

Choose a reason for hiding this comment

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

Could you show me an example?

Copy link
Collaborator Author

@amitsaha amitsaha Nov 24, 2020

Choose a reason for hiding this comment

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

How about we use kubectl to show the token review operation but use the token for the service token instead via the --token argument?

# TODO: Get the token from the secret object
kubectl apply -f t.yaml --token <token from above>

@amitsaha
Copy link
Collaborator Author

I think the TokenReview API is authentication, but when you use to verify the audience you are implementing custom authorization.

Completely agree with this. So should we just use authentication throughout?

@danielepolencic
Copy link
Contributor

Completely agree with this. So should we just use authentication throughout?
I think we need to pay more attention, particularly at the beginning. It's ok to say authorization where we do auth.

@amitsaha
Copy link
Collaborator Author

@danielepolencic i made a few updates related to authn/authz what do you think?

@amitsaha amitsaha force-pushed the micro_authentication branch from 87f809d to c187d92 Compare November 25, 2020 01:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants