-
Notifications
You must be signed in to change notification settings - Fork 276
/
provider.go
129 lines (111 loc) · 3.56 KB
/
provider.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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
//
// 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 sia
import (
"crypto"
"crypto/x509"
"crypto/x509/pkix"
"fmt"
gcpa "github.com/AthenZ/athenz/libs/go/sia/gcp/attestation"
"github.com/AthenZ/athenz/libs/go/sia/gcp/meta"
"github.com/AthenZ/athenz/libs/go/sia/host/ip"
"github.com/AthenZ/athenz/libs/go/sia/host/signature"
"github.com/AthenZ/athenz/libs/go/sia/host/utils"
"net"
"net/url"
)
type GCEProvider struct {
Name string
}
// GetName returns the name of the current provider
func (gce GCEProvider) GetName() string {
return gce.Name
}
// GetHostname returns the hostname as per the provider
func (gce GCEProvider) GetHostname(fqdn bool) string {
return utils.GetHostname(fqdn)
}
func (gce GCEProvider) AttestationData(_ string, _ crypto.PrivateKey, _ *signature.SignatureInfo) (string, error) {
result, err := meta.GetData("http://169.254.169.254", "/computeMetadata/v1/instance/service-accounts/default/identity?audience=https://zts.athenz.io&format=full")
if err == nil {
return string(result), nil
}
return "", fmt.Errorf("error while retriveing attestation data")
}
func (gce GCEProvider) PrepareKey(_ string) (crypto.PrivateKey, error) {
return "", fmt.Errorf("not implemented")
}
func (gce GCEProvider) GetCsrDn() pkix.Name {
return pkix.Name{}
}
func (gce GCEProvider) GetSanDns(_ string, _ bool, _ bool, _ []string) []string {
return nil
}
func (gce GCEProvider) GetSanUri(_ string, _ ip.Opts, _, _ string) []*url.URL {
return nil
}
func (gce GCEProvider) GetEmail(_ string) []string {
return nil
}
func (gce GCEProvider) GetRoleDnsNames(_ *x509.Certificate, _ string) []string {
return nil
}
func (gce GCEProvider) GetSanIp(_ map[string]bool, _ []net.IP, _ ip.Opts) []net.IP {
return nil
}
func (gce GCEProvider) GetSuffixes() []string {
return []string{}
}
func (gce GCEProvider) CloudAttestationData(base, svc, ztsServerName string) (string, error) {
return gcpa.New(base, svc, ztsServerName)
}
func (gce GCEProvider) GetAccountDomainServiceFromMeta(base string) (string, string, string, error) {
account, err := meta.GetProject(base)
if err != nil {
return "", "", "", err
}
domain, err := meta.GetDomain(base)
if err != nil {
return account, "", "", err
}
service, err := meta.GetService(base)
if err != nil {
return account, domain, "", err
}
return account, domain, service, nil
}
func (gce GCEProvider) GetAccessManagementProfileFromMeta(base string) (string, error) {
profile, err := meta.GetProfile(base)
if err != nil {
return "", err
}
return profile, nil
}
func (gce GCEProvider) GetAdditionalSshHostPrincipals(base string) (string, error) {
instanceName, err := meta.GetInstanceName(base)
if err != nil {
return "", err
}
project, err := meta.GetProject(base)
if err != nil {
return fmt.Sprintf("%s", instanceName), nil
}
instanceId, err := meta.GetInstanceId(base)
if err != nil {
return fmt.Sprintf("%s,%s.c.%s.internal", instanceName, instanceName, project), nil
}
return fmt.Sprintf("%s,compute.%s,%s.c.%s.internal", instanceName, instanceId, instanceName, project), nil
}