Skip to content

Commit

Permalink
further ziti identity naming cleanup (#369)
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelquigley committed Jul 14, 2023
1 parent 48cfaad commit 4713243
Show file tree
Hide file tree
Showing 15 changed files with 46 additions and 30 deletions.
10 changes: 5 additions & 5 deletions cmd/zrok/accessPrivate.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,20 +101,20 @@ func (cmd *accessPrivateCommand) run(_ *cobra.Command, args []string) {
case "tcpTunnel":
fe, err := tcpTunnel.NewFrontend(&tcpTunnel.FrontendConfig{
BindAddress: cmd.bindAddress,
IdentityName: "backend",
IdentityName: env.ShareIdentityName(),
ShrToken: args[0],
RequestsChan: requests,
})
if err != nil {
if !panicInstead {
tui.Error("unable to create private frontend", err)
tui.Error("unable to create private access", err)
}
panic(err)
}
go func() {
if err := fe.Run(); err != nil {
if !panicInstead {
tui.Error("error starting frontend", err)
tui.Error("error starting access", err)
}
panic(err)
}
Expand All @@ -123,7 +123,7 @@ func (cmd *accessPrivateCommand) run(_ *cobra.Command, args []string) {
case "udpTunnel":
fe, err := udpTunnel.NewFrontend(&udpTunnel.FrontendConfig{
BindAddress: cmd.bindAddress,
IdentityName: "backend",
IdentityName: env.ShareIdentityName(),
ShrToken: args[0],
RequestsChan: requests,
IdleTime: time.Minute,
Expand All @@ -144,7 +144,7 @@ func (cmd *accessPrivateCommand) run(_ *cobra.Command, args []string) {
}()

default:
cfg := proxy.DefaultFrontendConfig("backend")
cfg := proxy.DefaultFrontendConfig(env.ShareIdentityName())
cfg.ShrToken = shrToken
cfg.Address = cmd.bindAddress
cfg.RequestsChan = requests
Expand Down
4 changes: 2 additions & 2 deletions cmd/zrok/adminCreateIdentity.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func (cmd *adminCreateIdentity) run(_ *cobra.Command, args []string) {
if err != nil {
panic(err)
}
zif, err := env.ZitiIdentityFile(name)
zif, err := env.ZitiIdentityNamed(name)
if err != nil {
panic(err)
}
Expand All @@ -58,7 +58,7 @@ func (cmd *adminCreateIdentity) run(_ *cobra.Command, args []string) {
panic(err)
}

if err := env.SaveZitiIdentity(name, resp.Payload.Cfg); err != nil {
if err := env.SaveZitiIdentityNamed(name, resp.Payload.Cfg); err != nil {
panic(err)
}

Expand Down
2 changes: 1 addition & 1 deletion cmd/zrok/disable.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func (cmd *disableCommand) run(_ *cobra.Command, _ []string) {
}
panic(err)
}
if err := env.DeleteZitiIdentity("backend"); err != nil {
if err := env.DeleteZitiIdentityNamed(env.ShareIdentityName()); err != nil {
if !panicInstead {
tui.Error("error removing zrok backend identity", err)
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/zrok/enable.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ func (cmd *enableCommand) run(_ *cobra.Command, args []string) {
}
os.Exit(1)
}
if err := env.SaveZitiIdentity("backend", resp.Payload.Cfg); err != nil {
if err := env.SaveZitiIdentityNamed(env.ShareIdentityName(), resp.Payload.Cfg); err != nil {
if !cmd.headless && prg != nil {
prg.Send(fmt.Sprintf("there was an error writing the environment: %v", err))
prg.Quit()
Expand Down
2 changes: 1 addition & 1 deletion cmd/zrok/sharePrivate.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func (cmd *sharePrivateCommand) run(_ *cobra.Command, args []string) {
tui.Error("unable to load environment; did you 'zrok enable'?", nil)
}

zif, err := env.ZitiIdentityFile("backend")
zif, err := env.ZitiIdentityNamed(env.ShareIdentityName())
if err != nil {
if !panicInstead {
tui.Error("unable to load ziti identity configuration", err)
Expand Down
2 changes: 1 addition & 1 deletion cmd/zrok/sharePublic.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func (cmd *sharePublicCommand) run(_ *cobra.Command, args []string) {
tui.Error("unable to load environment; did you 'zrok enable'?", nil)
}

zif, err := env.ZitiIdentityFile("backend")
zif, err := env.ZitiIdentityNamed(env.ShareIdentityName())
if err != nil {
if !panicInstead {
tui.Error("unable to load ziti identity configuration", err)
Expand Down
2 changes: 1 addition & 1 deletion cmd/zrok/shareReserved.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func (cmd *shareReservedCommand) run(_ *cobra.Command, args []string) {
target = resp.Payload.BackendProxyEndpoint
}

zif, err := env.ZitiIdentityFile("backend")
zif, err := env.ZitiIdentityNamed(env.ShareIdentityName())
if err != nil {
if !panicInstead {
tui.Error("unable to load ziti identity configuration", err)
Expand Down
2 changes: 1 addition & 1 deletion cmd/zrok/testLoopPublic.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ func (l *looper) startup() {
}
l.env = env.Environment()

l.zif, err = env.ZitiIdentityFile("backend")
l.zif, err = env.ZitiIdentityNamed(env.ShareIdentityName())
if err != nil {
panic(err)
}
Expand Down
15 changes: 10 additions & 5 deletions controller/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,22 +36,27 @@ func Bootstrap(skipFrontend bool, inCfg *config.Config) error {
return errors.Wrap(err, "error connecting to the ziti edge management api")
}

env, err := environment.LoadRoot()
if err != nil {
return err
}

var frontendZId string
if !skipFrontend {
logrus.Info("creating identity for frontend ziti access")

if frontendZId, err = getIdentityId("frontend"); err == nil {
if frontendZId, err = getIdentityId(env.AccessIdentityName()); err == nil {
logrus.Infof("frontend identity: %v", frontendZId)
} else {
frontendZId, err = bootstrapIdentity("frontend", edge)
frontendZId, err = bootstrapIdentity(env.AccessIdentityName(), edge)
if err != nil {
panic(err)
}
}
if err := assertIdentity(frontendZId, edge); err != nil {
panic(err)
}
if err := assertErpForIdentity("frontend", frontendZId, edge); err != nil {
if err := assertErpForIdentity(env.AccessIdentityName(), frontendZId, edge); err != nil {
panic(err)
}

Expand Down Expand Up @@ -117,7 +122,7 @@ func getIdentityId(identityName string) (string, error) {
if err != nil {
return "", errors.Wrap(err, "error opening environment root")
}
zif, err := env.ZitiIdentityFile(identityName)
zif, err := env.ZitiIdentityNamed(identityName)
if err != nil {
return "", errors.Wrapf(err, "error opening identity '%v' from environment", identityName)
}
Expand Down Expand Up @@ -184,7 +189,7 @@ func bootstrapIdentity(name string, edge *rest_management_api_client.ZitiEdgeMan
if err != nil {
return "", errors.Wrapf(err, "error encoding identity config '%v'", name)
}
if err := env.SaveZitiIdentity(name, out.String()); err != nil {
if err := env.SaveZitiIdentityNamed(name, out.String()); err != nil {
return "", errors.Wrapf(err, "error saving identity config '%v'", name)
}
return zId, nil
Expand Down
2 changes: 1 addition & 1 deletion endpoints/proxy/frontend.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func NewFrontend(cfg *FrontendConfig) (*Frontend, error) {
if err != nil {
return nil, errors.Wrap(err, "error loading environment root")
}
zCfgPath, err := env.ZitiIdentityFile(cfg.IdentityName)
zCfgPath, err := env.ZitiIdentityNamed(cfg.IdentityName)
if err != nil {
return nil, errors.Wrapf(err, "error getting ziti identity '%v' from environment", cfg.IdentityName)
}
Expand Down
2 changes: 1 addition & 1 deletion endpoints/publicProxy/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func NewHTTP(cfg *Config) (*httpFrontend, error) {
if err != nil {
return nil, errors.Wrap(err, "error loading environment root")
}
zCfgPath, err := env.ZitiIdentityFile(cfg.Identity)
zCfgPath, err := env.ZitiIdentityNamed(cfg.Identity)
if err != nil {
return nil, errors.Wrapf(err, "error getting ziti identity '%v' from environment", cfg.Identity)
}
Expand Down
2 changes: 1 addition & 1 deletion endpoints/tcpTunnel/frontend.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func NewFrontend(cfg *FrontendConfig) (*Frontend, error) {
if err != nil {
return nil, errors.Wrap(err, "error loading environment root")
}
zCfgPath, err := env.ZitiIdentityFile(cfg.IdentityName)
zCfgPath, err := env.ZitiIdentityNamed(cfg.IdentityName)
if err != nil {
return nil, errors.Wrapf(err, "error getting ziti identity '%v' from environment", cfg.IdentityName)
}
Expand Down
2 changes: 1 addition & 1 deletion endpoints/udpTunnel/frontend.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ func NewFrontend(cfg *FrontendConfig) (*Frontend, error) {
if err != nil {
return nil, errors.Wrap(err, "error loading environment root")
}
zCfgPath, err := env.ZitiIdentityFile(cfg.IdentityName)
zCfgPath, err := env.ZitiIdentityNamed(cfg.IdentityName)
if err != nil {
return nil, errors.Wrapf(err, "error getting ziti identity '%v' from environment", cfg.IdentityName)
}
Expand Down
9 changes: 6 additions & 3 deletions environment/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,12 @@ type Root interface {
SetEnvironment(env *env_core.Environment) error
DeleteEnvironment() error

ZitiIdentityFile(name string) (string, error)
SaveZitiIdentity(name, data string) error
DeleteZitiIdentity(name string) error
AccessIdentityName() string
ShareIdentityName() string

ZitiIdentityNamed(name string) (string, error)
SaveZitiIdentityNamed(name, data string) error
DeleteZitiIdentityNamed(name string) error
}

func LoadRoot() (Root, error) {
Expand Down
18 changes: 13 additions & 5 deletions environment/env_v0_3/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,15 +116,23 @@ func (r *Root) IsEnabled() bool {
return r.env != nil
}

func (r *Root) ZitiIdentityFile(name string) (string, error) {
func (r *Root) AccessIdentityName() string {
return "frontend"
}

func (r *Root) ShareIdentityName() string {
return "backend"
}

func (r *Root) ZitiIdentityNamed(name string) (string, error) {
return identityFile(name)
}

func (r *Root) SaveZitiIdentity(name, data string) error {
func (r *Root) SaveZitiIdentityNamed(name, data string) error {
if err := assertMetadata(); err != nil {
return err
}
zif, err := r.ZitiIdentityFile(name)
zif, err := r.ZitiIdentityNamed(name)
if err != nil {
return err
}
Expand All @@ -137,8 +145,8 @@ func (r *Root) SaveZitiIdentity(name, data string) error {
return nil
}

func (r *Root) DeleteZitiIdentity(name string) error {
zif, err := r.ZitiIdentityFile(name)
func (r *Root) DeleteZitiIdentityNamed(name string) error {
zif, err := r.ZitiIdentityNamed(name)
if err != nil {
return errors.Wrapf(err, "error getting ziti identity file path for '%v'", name)
}
Expand Down

0 comments on commit 4713243

Please sign in to comment.