This repository has been archived by the owner on Apr 17, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
[nginx-ingress-controller] Allow authentication in Ingress rules #946
Merged
bprashanth
merged 4 commits into
kubernetes-retired:master
from
aledbf:nginx-ingress-authentication
May 31, 2016
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
nginx-ingress-controller |
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,126 @@ | ||
|
||
This example shows how to add authentication in a Ingress rule using a secret that contains a file generated with `htpasswd`. | ||
|
||
|
||
``` | ||
$ htpasswd -c auth foo | ||
New password: <bar> | ||
New password: | ||
Re-type new password: | ||
Adding password for user foo | ||
``` | ||
|
||
``` | ||
$ kubectl create secret generic basic-auth --from-file=auth | ||
secret "basic-auth" created | ||
``` | ||
|
||
``` | ||
$ kubectl get secret basic-auth -o yaml | ||
apiVersion: v1 | ||
data: | ||
auth: Zm9vOiRhcHIxJE9GRzNYeWJwJGNrTDBGSERBa29YWUlsSDkuY3lzVDAK | ||
kind: Secret | ||
metadata: | ||
name: basic-auth | ||
namespace: default | ||
type: Opaque | ||
``` | ||
|
||
``` | ||
echo " | ||
apiVersion: extensions/v1beta1 | ||
kind: Ingress | ||
metadata: | ||
name: ingress-with-auth | ||
annotations: | ||
# type of authentication | ||
ingress-nginx.kubernetes.io/auth-type: basic | ||
# name of the secret that contains the user/password definitions | ||
ingress-nginx.kubernetes.io/auth-secret: basic-auth | ||
# message to display with an appropiate context why the authentication is required | ||
ingress-nginx.kubernetes.io/auth-realm: "Authentication Required - foo" | ||
spec: | ||
rules: | ||
- host: foo.bar.com | ||
http: | ||
paths: | ||
- path: / | ||
backend: | ||
serviceName: echoheaders | ||
servicePort: 80 | ||
" | kubectl create -f - | ||
``` | ||
|
||
``` | ||
$ curl -v http://10.2.29.4/ -H 'Host: foo.bar.com' | ||
* Trying 10.2.29.4... | ||
* Connected to 10.2.29.4 (10.2.29.4) port 80 (#0) | ||
> GET / HTTP/1.1 | ||
> Host: foo.bar.com | ||
> User-Agent: curl/7.43.0 | ||
> Accept: */* | ||
> | ||
< HTTP/1.1 401 Unauthorized | ||
< Server: nginx/1.10.0 | ||
< Date: Wed, 11 May 2016 05:27:23 GMT | ||
< Content-Type: text/html | ||
< Content-Length: 195 | ||
< Connection: keep-alive | ||
< WWW-Authenticate: Basic realm="Authentication Required - foo" | ||
< | ||
<html> | ||
<head><title>401 Authorization Required</title></head> | ||
<body bgcolor="white"> | ||
<center><h1>401 Authorization Required</h1></center> | ||
<hr><center>nginx/1.10.0</center> | ||
</body> | ||
</html> | ||
* Connection #0 to host 10.2.29.4 left intact | ||
``` | ||
|
||
``` | ||
$ curl -v http://10.2.29.4/ -H 'Host: foo.bar.com' -u 'foo:bar' | ||
* Trying 10.2.29.4... | ||
* Connected to 10.2.29.4 (10.2.29.4) port 80 (#0) | ||
* Server auth using Basic with user 'foo' | ||
> GET / HTTP/1.1 | ||
> Host: foo.bar.com | ||
> Authorization: Basic Zm9vOmJhcg== | ||
> User-Agent: curl/7.43.0 | ||
> Accept: */* | ||
> | ||
< HTTP/1.1 200 OK | ||
< Server: nginx/1.10.0 | ||
< Date: Wed, 11 May 2016 06:05:26 GMT | ||
< Content-Type: text/plain | ||
< Transfer-Encoding: chunked | ||
< Connection: keep-alive | ||
< Vary: Accept-Encoding | ||
< | ||
CLIENT VALUES: | ||
client_address=10.2.29.4 | ||
command=GET | ||
real path=/ | ||
query=nil | ||
request_version=1.1 | ||
request_uri=http://foo.bar.com:8080/ | ||
|
||
SERVER VALUES: | ||
server_version=nginx: 1.9.11 - lua: 10001 | ||
|
||
HEADERS RECEIVED: | ||
accept=*/* | ||
authorization=Basic Zm9vOmJhcg== | ||
connection=close | ||
host=foo.bar.com | ||
user-agent=curl/7.43.0 | ||
x-forwarded-for=10.2.29.1 | ||
x-forwarded-host=foo.bar.com | ||
x-forwarded-port=80 | ||
x-forwarded-proto=http | ||
x-real-ip=10.2.29.1 | ||
BODY: | ||
* Connection #0 to host 10.2.29.4 left intact | ||
-no body in request- | ||
``` |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please add text inbetween the quoted blocks explaining what each block is doing