This repository has been archived by the owner on Jan 31, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
main.go
77 lines (65 loc) · 2.58 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/*
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package main
import (
"flag"
"log"
"net/http"
"github.com/dims/k8s-keystone-auth/pkg/authenticator/token/keystone"
"github.com/dims/k8s-keystone-auth/pkg/identity/webhook"
"k8s.io/apiserver/pkg/authentication/authenticator"
"k8s.io/apiserver/pkg/authorization/authorizer"
)
func webhookServer(authenticator authenticator.Token, authorizer authorizer.Authorizer) http.Handler {
return &webhook.WebhookHandler{
Authenticator: authenticator,
Authorizer: authorizer,
}
}
var (
listenAddr string
tlsCertFile string
tlsPrivateKey string
keystoneURL string
keystoneCaFile string
policyFile string
)
func main() {
flag.StringVar(&listenAddr, "listen", "localhost:8443", "<address>:<port> to listen on")
flag.StringVar(&tlsCertFile, "tls-cert-file", "", "File containing the default x509 Certificate for HTTPS.")
flag.StringVar(&tlsPrivateKey, "tls-private-key-file", "", "File containing the default x509 private key matching --tls-cert-file.")
flag.StringVar(&keystoneURL, "keystone-url", "http://localhost/identity/v3/", "URL for the OpenStack Keystone API")
flag.StringVar(&keystoneCaFile, "keystone-ca-file", "", "File containing the certificate authority for Keystone Service.")
flag.StringVar(&policyFile, "keystone-policy-file", "", "File containing the policy.")
flag.Parse()
if tlsCertFile == "" || tlsPrivateKey == "" {
log.Fatal("Please specify --tls-cert-file and --tls-private-key-file arguments.")
}
if policyFile == "" {
log.Printf("Argument --keystone-policy-file missing. Only keystone authentication will work. Use RBAC for authorization.")
}
authentication_handler, err := keystone.NewKeystoneAuthenticator(keystoneURL, keystoneCaFile)
if err != nil {
log.Fatal(err.Error())
}
authorization_handler, err := keystone.NewKeystoneAuthorizer(keystoneURL, keystoneCaFile, policyFile)
if err != nil {
log.Fatal(err.Error())
}
http.Handle("/webhook", webhookServer(authentication_handler, authorization_handler))
log.Println("Starting webhook..")
log.Fatal(
http.ListenAndServeTLS(":8443",
tlsCertFile,
tlsPrivateKey,
nil))
}