-
Notifications
You must be signed in to change notification settings - Fork 276
/
main.go
111 lines (92 loc) · 3.73 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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
//
// Copyright The Athenz Authors
//
// 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"
"fmt"
"log"
"os"
"strings"
"github.com/AthenZ/athenz/libs/go/sia/aws/agent"
"github.com/AthenZ/athenz/libs/go/sia/aws/meta"
"github.com/AthenZ/athenz/libs/go/sia/aws/options"
"github.com/AthenZ/athenz/libs/go/sia/host/utils"
"github.com/AthenZ/athenz/provider/aws/sia-eks"
)
// Following can be set by the build script using LDFLAGS
var Version string
const siaMainDir = "/var/lib/sia"
func main() {
cmd := flag.String("cmd", "", "optional sub command to run")
eksMetaEndPoint := flag.String("meta", "http://169.254.169.254:80", "meta endpoint")
ztsEndPoint := flag.String("zts", "", "Athenz Token Service (ZTS) endpoint")
ztsServerName := flag.String("ztsservername", "", "ZTS server name for tls connections (optional)")
ztsCACert := flag.String("ztscacert", "", "Athenz Token Service (ZTS) CA certificate file (optional)")
dnsDomains := flag.String("dnsdomains", "", "DNS Domains associated with the provider")
ztsPort := flag.Int("ztsport", 4443, "Athenz Token Service (ZTS) port number")
pConf := flag.String("config", "/etc/sia/sia_config", "The config file to run against")
useRegionalSTS := flag.Bool("regionalsts", false, "Use regional STS endpoint instead of global")
providerPrefix := flag.String("providerprefix", "", "Provider name prefix e.g athenz.aws")
displayVersion := flag.Bool("version", false, "Display version information")
udsPath := flag.String("uds", "", "uds path")
accessProfileConf := flag.String("profileconfig", "/etc/sia/profile_config", "The user access management profile config file")
flag.Parse()
if *displayVersion {
fmt.Println(Version)
os.Exit(0)
}
log.SetFlags(log.LstdFlags)
if *ztsEndPoint == "" {
log.Fatalln("missing zts argument")
}
ztsUrl := fmt.Sprintf("https://%s:%d/zts/v1", *ztsEndPoint, *ztsPort)
if *dnsDomains == "" {
log.Fatalln("missing dnsdomains argument")
}
if *providerPrefix == "" {
log.Fatalln("missing providerprefix argument")
}
log.Printf("SIA-EKS version: %s \n", Version)
region := meta.GetRegion(*eksMetaEndPoint, true)
config, configAccount, accessProfileConfig, err := sia.GetEKSConfig(*pConf, *accessProfileConf, *eksMetaEndPoint, *useRegionalSTS, region)
if err != nil {
log.Fatalf("Unable to formulate configuration objects, error: %v\n", err)
}
opts, err := options.NewOptions(config, configAccount, accessProfileConfig, siaMainDir, Version, *useRegionalSTS, region)
if err != nil {
log.Fatalf("Unable to formulate options, error: %v\n", err)
}
opts.MetaEndPoint = *eksMetaEndPoint
opts.Ssh = false
opts.ZTSCACertFile = *ztsCACert
opts.ZTSServerName = *ztsServerName
opts.ZTSAWSDomains = strings.Split(*dnsDomains, ",")
spiffeNamespace, addlSanDNSEntries := utils.GetK8SHostnames("cluster.local", false)
opts.SpiffeNamespace = spiffeNamespace
if len(addlSanDNSEntries) > 0 {
opts.AddlSanDNSEntries = append(opts.AddlSanDNSEntries, addlSanDNSEntries...)
}
opts.InstanceId = sia.GetEKSPodId()
if *udsPath != "" {
opts.SDSUdsPath = *udsPath
}
provider := sia.EKSProvider{
Name: fmt.Sprintf("%s.%s", *providerPrefix, region),
}
opts.Provider = provider
agent.SetupAgent(opts, siaMainDir, "")
agent.RunAgent(*cmd, ztsUrl, opts)
}