Skip to content

Commit

Permalink
Remove spire dependency (#348)
Browse files Browse the repository at this point in the history
* refactored

Signed-off-by: Maia Iyer <maia.raj.iyer@gmail.com>

* Removed run dependency backend

Signed-off-by: Maia Iyer <maia.raj.iyer@gmail.com>

---------

Signed-off-by: Maia Iyer <maia.raj.iyer@gmail.com>
  • Loading branch information
maia-iyer authored Feb 23, 2024
1 parent 1ceeacb commit 0e56df2
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 2,042 deletions.
11 changes: 11 additions & 0 deletions api/agent/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,17 @@ type TornjakSpireServerInfo struct {
VerboseConfig string `json:"verboseConfig"`
}

// pared down version of full Server Config type spire/cmd/spire-server/cli/run
// we curently need only extract the trust domain
type SpireServerConfig struct {
TrustDomain string `hcl:"trust_domain"`
}

type SPIREConfig struct {
Server *SpireServerConfig `hcl:"server"`
Plugins ast.Node `hcl:"plugins"`
}

type TornjakConfig struct {
Server *serverConfig `hcl:"server"`
Plugins *ast.Node `hcl:"plugins"`
Expand Down
52 changes: 33 additions & 19 deletions cmd/agent/main.go
Original file line number Diff line number Diff line change
@@ -1,23 +1,21 @@
package main

import (
"encoding/json"
"fmt"
"log"
"os"
"path/filepath"

"github.com/hashicorp/hcl"
"github.com/pkg/errors"
"github.com/spiffe/spire/cmd/spire-server/cli/run"
"github.com/spiffe/spire/pkg/common/catalog"
agentapi "github.com/spiffe/tornjak/api/agent"
"github.com/urfave/cli/v2"
)

type cliOptions struct {
genericOptions struct {
configFile string // TODO change name
spireFile string
tornjakFile string
expandEnv bool
}
Expand All @@ -31,7 +29,7 @@ func main() {
Name: "spire-config",
Value: "",
Usage: "Config file path for spire server",
Destination: &opt.genericOptions.configFile,
Destination: &opt.genericOptions.spireFile,
Required: false,
},
&cli.StringFlag{
Expand Down Expand Up @@ -75,16 +73,14 @@ func main() {

func runTornjakCmd(cmd string, opt cliOptions) error {
// parse configs
spire_config_file := opt.genericOptions.configFile
spire_config_file := opt.genericOptions.spireFile
var serverInfo = agentapi.TornjakSpireServerInfo{}
if spire_config_file != "" { // SPIRE config given
config, err := run.ParseFile(spire_config_file, false)
configData, err := getConfigString(spire_config_file, false)
if err != nil {
// Hide internal error since it is specific to arguments of originating library
// i.e. asks to set -config which is different flag in Tornjak
return errors.New("Unable to parse the config file provided")
return errors.Errorf("Could not find given SPIRE Config file: %v", err)
}
serverInfo, err = GetServerInfo(config)
serverInfo, err = GetServerInfo(configData)
if err != nil {
log.Fatalf("Error: %v", err)
}
Expand All @@ -102,7 +98,7 @@ func runTornjakCmd(cmd string, opt cliOptions) error {
} else {
fmt.Println(serverInfo)
}
tornjakInfo, err := getTornjakConfig(opt.genericOptions.tornjakFile, opt.genericOptions.expandEnv)
tornjakInfo, err := getConfigString(opt.genericOptions.tornjakFile, opt.genericOptions.expandEnv)
if err != nil {
log.Fatalf("Error: %v", err)
}
Expand All @@ -121,7 +117,14 @@ func runTornjakCmd(cmd string, opt cliOptions) error {

}

func GetServerInfo(config *run.Config) (agentapi.TornjakSpireServerInfo, error) {
func GetServerInfo(configData string) (agentapi.TornjakSpireServerInfo, error) {
// we extract TrustDomain and Plugin Info
config, err := parseSPIREConfig(configData)
if err != nil {
return agentapi.TornjakSpireServerInfo{}, errors.Errorf("Could not parse SPIRE Config: %v", err)
}


if config.Plugins == nil {
return agentapi.TornjakSpireServerInfo{}, errors.New("config plugins map should not be nil")
}
Expand All @@ -142,8 +145,7 @@ func GetServerInfo(config *run.Config) (agentapi.TornjakSpireServerInfo, error)

serverInfo += "\n\n"
serverInfo += "Server Info"
s, _ := json.MarshalIndent(config.Server, "", "\t")
serverInfo += string(s)
serverInfo += configData

return agentapi.TornjakSpireServerInfo{
Plugins: pluginMap,
Expand All @@ -152,7 +154,7 @@ func GetServerInfo(config *run.Config) (agentapi.TornjakSpireServerInfo, error)
}, nil
}

func getTornjakConfig(path string, expandEnv bool) (string, error) {
func getConfigString(path string, expandEnv bool) (string, error) {
if path == "" {
return "", nil
}
Expand All @@ -163,13 +165,13 @@ func getTornjakConfig(path string, expandEnv bool) (string, error) {
if os.IsNotExist(err) {
absPath, err := filepath.Abs(path)
if err != nil {
msg := "could not determine CWD; tornjak config file not found at %s: use -tornjak-config"
msg := "could not determine CWD; config file not found at %s"
return "", fmt.Errorf(msg, path)
}
msg := "could not find tornjak config file %s: please use the -tornjak-config flag"
msg := "could not find config file %s"
return "", fmt.Errorf(msg, absPath)
}
return "", fmt.Errorf("unable to read tornjak configuration at %q: %w", path, err)
return "", fmt.Errorf("unable to read configuration file at %q: %w", path, err)
}
data := string(byteData)

Expand All @@ -181,6 +183,18 @@ func getTornjakConfig(path string, expandEnv bool) (string, error) {
return data, nil
}

// we use our own returned SPIRE Config type to extract information
// needed specifically by the frontend
func parseSPIREConfig(data string) (*agentapi.SPIREConfig, error) {
c := &agentapi.SPIREConfig{}

if err := hcl.Decode(&c, data); err != nil {
return nil, fmt.Errorf("unable to decode SPIRE configuration: %w", err)
}

return c, nil
}

// below copied from spire/cmd/spire-server/cli/run/run.go, but with TornjakConfig
func parseTornjakConfig(path string, expandEnv bool) (*agentapi.TornjakConfig, error) {
c := &agentapi.TornjakConfig{}
Expand All @@ -190,7 +204,7 @@ func parseTornjakConfig(path string, expandEnv bool) (*agentapi.TornjakConfig, e
}

// friendly error if file is missing
data, err := getTornjakConfig(path, expandEnv)
data, err := getConfigString(path, expandEnv)
if err != nil {
return nil, err
}
Expand Down
140 changes: 1 addition & 139 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -17,182 +17,44 @@ require (
)

require (
cloud.google.com/go v0.110.0 // indirect
cloud.google.com/go/compute v1.19.1 // indirect
cloud.google.com/go/compute/metadata v0.2.3 // indirect
cloud.google.com/go/iam v1.0.0 // indirect
cloud.google.com/go/kms v1.10.1 // indirect
cloud.google.com/go/longrunning v0.4.1 // indirect
cloud.google.com/go/security v1.14.0 // indirect
cloud.google.com/go/storage v1.30.1 // indirect
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.6.0 // indirect
github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.2.2 // indirect
github.com/Azure/azure-sdk-for-go/sdk/internal v1.3.0 // indirect
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute v1.0.0 // indirect
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/network/armnetwork v1.1.0 // indirect
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armresources v1.1.1 // indirect
github.com/AzureAD/microsoft-authentication-library-for-go v0.9.0 // indirect
github.com/DataDog/datadog-go v3.2.0+incompatible // indirect
github.com/GoogleCloudPlatform/cloudsql-proxy v1.33.6 // indirect
github.com/Masterminds/goutils v1.1.1 // indirect
github.com/Masterminds/semver/v3 v3.2.0 // indirect
github.com/Masterminds/sprig/v3 v3.2.3 // indirect
github.com/Microsoft/go-winio v0.6.1 // indirect
github.com/OneOfOne/xxhash v1.2.8 // indirect
github.com/agnivade/levenshtein v1.1.1 // indirect
github.com/andres-erbsen/clock v0.0.0-20160526145045-9e14626cd129 // indirect
github.com/armon/go-metrics v0.4.1 // indirect
github.com/armon/go-radix v1.0.0 // indirect
github.com/aws/aws-sdk-go-v2 v1.18.0 // indirect
github.com/aws/aws-sdk-go-v2/config v1.18.23 // indirect
github.com/aws/aws-sdk-go-v2/credentials v1.13.22 // indirect
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.3 // indirect
github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.33 // indirect
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.27 // indirect
github.com/aws/aws-sdk-go-v2/internal/ini v1.3.34 // indirect
github.com/aws/aws-sdk-go-v2/service/acmpca v1.21.0 // indirect
github.com/aws/aws-sdk-go-v2/service/ec2 v1.96.1 // indirect
github.com/aws/aws-sdk-go-v2/service/iam v1.19.0 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.27 // indirect
github.com/aws/aws-sdk-go-v2/service/kms v1.21.1 // indirect
github.com/aws/aws-sdk-go-v2/service/secretsmanager v1.19.0 // indirect
github.com/aws/aws-sdk-go-v2/service/sso v1.12.10 // indirect
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.14.10 // indirect
github.com/aws/aws-sdk-go-v2/service/sts v1.18.11 // indirect
github.com/aws/smithy-go v1.13.5 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/bgentry/speakeasy v0.1.0 // indirect
github.com/blang/semver/v4 v4.0.0 // indirect
github.com/cenkalti/backoff/v3 v3.2.2 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/emicklei/go-restful/v3 v3.9.0 // indirect
github.com/evanphx/json-patch/v5 v5.6.0 // indirect
github.com/fatih/color v1.13.0 // indirect
github.com/ghodss/yaml v1.0.0 // indirect
github.com/go-jose/go-jose/v3 v3.0.1 // indirect
github.com/go-logr/logr v1.2.4 // indirect
github.com/go-ole/go-ole v1.2.6 // indirect
github.com/go-openapi/jsonpointer v0.19.6 // indirect
github.com/go-openapi/jsonreference v0.20.1 // indirect
github.com/go-openapi/swag v0.22.3 // indirect
github.com/go-sql-driver/mysql v1.7.1 // indirect
github.com/gobwas/glob v0.2.3 // indirect
github.com/gofrs/uuid/v5 v5.0.0 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/google/gnostic v0.5.7-v3refs // indirect
github.com/google/go-cmp v0.5.9 // indirect
github.com/google/go-tpm v0.3.3 // indirect
github.com/google/gofuzz v1.2.0 // indirect
github.com/google/s2a-go v0.1.3 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/googleapis/enterprise-certificate-proxy v0.2.3 // indirect
github.com/googleapis/gax-go/v2 v2.8.0 // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
github.com/hashicorp/go-hclog v1.5.0 // indirect
github.com/hashicorp/go-immutable-radix v1.3.1 // indirect
github.com/hashicorp/go-multierror v1.1.1 // indirect
github.com/hashicorp/go-plugin v1.4.6 // indirect
github.com/hashicorp/go-retryablehttp v0.7.2 // indirect
github.com/hashicorp/go-rootcerts v1.0.2 // indirect
github.com/hashicorp/go-secure-stdlib/parseutil v0.1.7 // indirect
github.com/hashicorp/go-secure-stdlib/strutil v0.1.2 // indirect
github.com/hashicorp/go-sockaddr v1.0.2 // indirect
github.com/hashicorp/golang-lru v0.5.4 // indirect
github.com/hashicorp/vault/api v1.9.1 // indirect
github.com/hashicorp/yamux v0.1.1 // indirect
github.com/huandu/xstrings v1.3.3 // indirect
github.com/imdario/mergo v0.3.15 // indirect
github.com/imkira/go-observer v1.0.3 // indirect
github.com/jinzhu/gorm v1.9.16 // indirect
github.com/jinzhu/inflection v1.0.0 // indirect
github.com/jmespath/go-jmespath v0.4.0 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/kylelemons/godebug v1.1.0 // indirect
github.com/lib/pq v1.10.9 // indirect
github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.16 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
github.com/mitchellh/cli v1.1.5 // indirect
github.com/mitchellh/copystructure v1.2.0 // indirect
github.com/mitchellh/go-homedir v1.1.0 // indirect
github.com/mitchellh/go-testing-interface v1.14.1 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/mitchellh/reflectwalk v1.0.2 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/oklog/run v1.1.0 // indirect
github.com/open-policy-agent/opa v0.52.0 // indirect
github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/posener/complete v1.2.3 // indirect
github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c // indirect
github.com/prometheus/client_golang v1.15.1 // indirect
github.com/prometheus/client_model v0.3.0 // indirect
github.com/prometheus/common v0.42.0 // indirect
github.com/prometheus/procfs v0.9.0 // indirect
github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/ryanuber/go-glob v1.0.0 // indirect
github.com/shirou/gopsutil/v3 v3.23.4 // indirect
github.com/shoenig/go-m1cpu v0.1.5 // indirect
github.com/shopspring/decimal v1.2.0 // indirect
github.com/sirupsen/logrus v1.9.0 // indirect
github.com/spf13/cast v1.5.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/spiffe/go-spiffe/v2 v2.1.4 // indirect
github.com/spiffe/spire-plugin-sdk v1.4.4-0.20230224144655-648f8c740f73 // indirect
github.com/stretchr/testify v1.8.2 // indirect
github.com/tchap/go-patricia/v2 v2.3.1 // indirect
github.com/tklauser/go-sysconf v0.3.11 // indirect
github.com/tklauser/numcpus v0.6.0 // indirect
github.com/stretchr/objx v0.5.0 // indirect
github.com/twmb/murmur3 v1.1.6 // indirect
github.com/uber-go/tally/v4 v4.1.7 // indirect
github.com/xeipuuv/gojsonpointer v0.0.0-20190905194746-02993c407bfb // indirect
github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 // indirect
github.com/yashtewari/glob-intersection v0.1.0 // indirect
github.com/yusufpapurcu/wmi v1.2.2 // indirect
github.com/zeebo/errs v1.3.0 // indirect
go.opencensus.io v0.24.0 // indirect
go.uber.org/atomic v1.10.0 // indirect
go.uber.org/multierr v1.9.0 // indirect
go.uber.org/zap v1.24.0 // indirect
golang.org/x/crypto v0.17.0 // indirect
golang.org/x/mod v0.10.0 // indirect
golang.org/x/net v0.17.0 // indirect
golang.org/x/oauth2 v0.7.0 // indirect
golang.org/x/sync v0.2.0 // indirect
golang.org/x/sys v0.15.0 // indirect
golang.org/x/term v0.15.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/time v0.3.0 // indirect
golang.org/x/tools v0.8.0 // indirect
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 // indirect
google.golang.org/api v0.121.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/genproto v0.0.0-20230410155749-daa745c078e1 // indirect
google.golang.org/protobuf v1.30.0 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/square/go-jose.v2 v2.6.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
k8s.io/api v0.27.1 // indirect
k8s.io/apimachinery v0.27.1 // indirect
k8s.io/client-go v0.27.1 // indirect
k8s.io/klog/v2 v2.90.1 // indirect
k8s.io/kube-aggregator v0.27.1 // indirect
k8s.io/kube-openapi v0.0.0-20230308215209-15aac26d736a // indirect
k8s.io/utils v0.0.0-20230209194617-a36077c30491 // indirect
sigs.k8s.io/controller-runtime v0.14.6 // indirect
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.2.3 // indirect
sigs.k8s.io/yaml v1.3.0 // indirect
)
Loading

0 comments on commit 0e56df2

Please sign in to comment.