wiring in the environment ziti identity for better correlation in logs (#90)

This commit is contained in:
Michael Quigley 2022-11-08 15:07:18 -05:00
parent b9c9e62910
commit c7dc3d5d71
No known key found for this signature in database
GPG Key ID: 9B60314A9DD20A62
5 changed files with 48 additions and 39 deletions

View File

@ -29,6 +29,11 @@ func (self *disableHandler) Handle(params identity.DisableParams, principal *res
logrus.Errorf("identity check failed: %v", err)
return identity.NewDisableUnauthorized()
}
env, err := str.GetEnvironment(envId, tx)
if err != nil {
logrus.Errorf("error getting environment: %v", err)
return identity.NewDisableInternalServerError()
}
edge, err := edgeClient()
if err != nil {
logrus.Errorf("error getting edge client: %v", err)
@ -42,7 +47,7 @@ func (self *disableHandler) Handle(params identity.DisableParams, principal *res
logrus.Errorf("error removing environment: %v", err)
return identity.NewDisableInternalServerError()
}
if err := deleteEdgeRouterPolicy(params.Body.Identity, edge); err != nil {
if err := deleteEdgeRouterPolicy(env.ZId, params.Body.Identity, edge); err != nil {
logrus.Errorf("error deleting edge router policy: %v", err)
return identity.NewDisableInternalServerError()
}
@ -70,29 +75,33 @@ func (self *disableHandler) checkZitiIdentity(id string, principal *rest_model_z
}
func (self *disableHandler) removeServicesForEnvironment(envId int, tx *sqlx.Tx, edge *rest_management_api_client.ZitiEdgeManagement) error {
env, err := str.GetEnvironment(envId, tx)
if err != nil {
return err
}
svcs, err := str.FindServicesForEnvironment(envId, tx)
if err != nil {
return err
}
for _, svc := range svcs {
svcName := svc.Name
logrus.Infof("garbage collecting service '%v'", svcName)
if err := deleteServiceEdgeRouterPolicy(svcName, edge); err != nil {
logrus.Infof("garbage collecting service '%v' for environment '%v'", svcName, env.ZId)
if err := deleteServiceEdgeRouterPolicy(env.ZId, svcName, edge); err != nil {
logrus.Error(err)
}
if err := deleteServicePolicyDial(svcName, edge); err != nil {
if err := deleteServicePolicyDial(env.ZId, svcName, edge); err != nil {
logrus.Error(err)
}
if err := deleteServicePolicyBind(svcName, edge); err != nil {
if err := deleteServicePolicyBind(env.ZId, svcName, edge); err != nil {
logrus.Error(err)
}
if err := deleteConfig(svcName, edge); err != nil {
if err := deleteConfig(env.ZId, svcName, edge); err != nil {
logrus.Error(err)
}
if err := deleteService(svc.ZId, edge); err != nil {
if err := deleteService(env.ZId, svc.ZId, edge); err != nil {
logrus.Error(err)
}
logrus.Infof("removed service '%v'", svc.Name)
logrus.Infof("removed service '%v' for environment '%v'", svc.Name, env.ZId)
}
return nil
}

View File

@ -14,7 +14,7 @@ import (
"time"
)
func deleteServiceEdgeRouterPolicy(svcName string, edge *rest_management_api_client.ZitiEdgeManagement) error {
func deleteServiceEdgeRouterPolicy(envZId, svcName string, edge *rest_management_api_client.ZitiEdgeManagement) error {
filter := fmt.Sprintf("name=\"%v\"", svcName)
limit := int64(1)
offset := int64(0)
@ -40,22 +40,22 @@ func deleteServiceEdgeRouterPolicy(svcName string, edge *rest_management_api_cli
if err != nil {
return err
}
logrus.Infof("deleted service edge router policy '%v'", serpId)
logrus.Infof("deleted service edge router policy '%v' for environment '%v'", serpId, envZId)
} else {
logrus.Infof("did not find a service edge router policy")
}
return nil
}
func deleteServicePolicyBind(svcName string, edge *rest_management_api_client.ZitiEdgeManagement) error {
return deleteServicePolicy(fmt.Sprintf("name=\"%v-backend\"", svcName), edge)
func deleteServicePolicyBind(envZId, svcName string, edge *rest_management_api_client.ZitiEdgeManagement) error {
return deleteServicePolicy(envZId, fmt.Sprintf("name=\"%v-backend\"", svcName), edge)
}
func deleteServicePolicyDial(svcName string, edge *rest_management_api_client.ZitiEdgeManagement) error {
return deleteServicePolicy(fmt.Sprintf("name=\"%v-dial\"", svcName), edge)
func deleteServicePolicyDial(envZId, svcName string, edge *rest_management_api_client.ZitiEdgeManagement) error {
return deleteServicePolicy(envZId, fmt.Sprintf("name=\"%v-dial\"", svcName), edge)
}
func deleteServicePolicy(filter string, edge *rest_management_api_client.ZitiEdgeManagement) error {
func deleteServicePolicy(envZId, filter string, edge *rest_management_api_client.ZitiEdgeManagement) error {
limit := int64(1)
offset := int64(0)
listReq := &service_policy.ListServicePoliciesParams{
@ -80,14 +80,14 @@ func deleteServicePolicy(filter string, edge *rest_management_api_client.ZitiEdg
if err != nil {
return err
}
logrus.Infof("deleted service policy '%v'", spId)
logrus.Infof("deleted service policy '%v' for environment '%v'", spId, envZId)
} else {
logrus.Infof("did not find a service policy")
}
return nil
}
func deleteConfig(svcName string, edge *rest_management_api_client.ZitiEdgeManagement) error {
func deleteConfig(envZId, svcName string, edge *rest_management_api_client.ZitiEdgeManagement) error {
filter := fmt.Sprintf("name=\"%v\"", svcName)
limit := int64(0)
offset := int64(0)
@ -112,12 +112,12 @@ func deleteConfig(svcName string, edge *rest_management_api_client.ZitiEdgeManag
if err != nil {
return err
}
logrus.Infof("deleted config '%v'", *cfg.ID)
logrus.Infof("deleted config '%v' for '%v'", *cfg.ID, envZId)
}
return nil
}
func deleteService(svcId string, edge *rest_management_api_client.ZitiEdgeManagement) error {
func deleteService(envZId, svcId string, edge *rest_management_api_client.ZitiEdgeManagement) error {
req := &service.DeleteServiceParams{
ID: svcId,
Context: context.Background(),
@ -127,12 +127,12 @@ func deleteService(svcId string, edge *rest_management_api_client.ZitiEdgeManage
if err != nil {
return err
}
logrus.Infof("deleted service '%v'", svcId)
logrus.Infof("deleted service '%v' for environment '%v'", svcId, envZId)
return nil
}
func deleteEdgeRouterPolicy(id string, edge *rest_management_api_client.ZitiEdgeManagement) error {
filter := fmt.Sprintf("name=\"zrok-%v\"", id)
func deleteEdgeRouterPolicy(envZId, id string, edge *rest_management_api_client.ZitiEdgeManagement) error {
filter := fmt.Sprintf("name=\"%v\"", id)
limit := int64(0)
offset := int64(0)
listReq := &edge_router_policy.ListEdgeRouterPoliciesParams{
@ -156,7 +156,7 @@ func deleteEdgeRouterPolicy(id string, edge *rest_management_api_client.ZitiEdge
if err != nil {
return err
}
logrus.Infof("deleted edge router policy '%v'", erpId)
logrus.Infof("deleted edge router policy '%v' for environment '%v'", erpId, envZId)
} else {
logrus.Infof("found '%d' edge router policies, expected 1", len(listResp.Payload.Data))
}
@ -173,6 +173,6 @@ func deleteIdentity(id string, edge *rest_management_api_client.ZitiEdgeManageme
if err != nil {
return err
}
logrus.Infof("deleted identity '%v'", id)
logrus.Infof("deleted environment identity '%v'", id)
return nil
}

View File

@ -69,7 +69,7 @@ func (self *enableHandler) Handle(params identity.EnableParams, principal *rest_
logrus.Errorf("error committing: %v", err)
return identity.NewCreateAccountInternalServerError()
}
logrus.Infof("recorded identity '%v' with id '%v' for '%v'", ident.Payload.Data.ID, envId, principal.Email)
logrus.Infof("created environment for '%v', with ziti identity '%v', and database id '%v'", principal.Email, ident.Payload.Data.ID, envId)
resp := identity.NewEnableCreated().WithPayload(&rest_model_zrok.EnableResponse{
Identity: ident.Payload.Data.ID,
@ -159,7 +159,7 @@ func (self *enableHandler) createEdgeRouterPolicy(id string, edge *rest_manageme
if err != nil {
return err
}
logrus.Infof("created edge router policy '%v'", resp.Payload.Data.ID)
logrus.Infof("created edge router policy '%v' for ziti identity '%v'", resp.Payload.Data.ID, id)
return nil
}

View File

@ -71,19 +71,19 @@ func gcServices(edge *rest_management_api_client.ZitiEdgeManagement, liveMap map
for _, svc := range listResp.Payload.Data {
if _, found := liveMap[*svc.Name]; !found {
logrus.Infof("garbage collecting, zitiSvcId='%v', zrokSvcId='%v'", *svc.ID, *svc.Name)
if err := deleteServiceEdgeRouterPolicy(*svc.Name, edge); err != nil {
if err := deleteServiceEdgeRouterPolicy("gc", *svc.Name, edge); err != nil {
logrus.Errorf("error garbage collecting service edge router policy: %v", err)
}
if err := deleteServicePolicyDial(*svc.Name, edge); err != nil {
if err := deleteServicePolicyDial("gc", *svc.Name, edge); err != nil {
logrus.Errorf("error garbage collecting service dial policy: %v", err)
}
if err := deleteServicePolicyBind(*svc.Name, edge); err != nil {
if err := deleteServicePolicyBind("gc", *svc.Name, edge); err != nil {
logrus.Errorf("error garbage collecting service bind policy: %v", err)
}
if err := deleteConfig(*svc.Name, edge); err != nil {
if err := deleteConfig("gc", *svc.Name, edge); err != nil {
logrus.Errorf("error garbage collecting config: %v", err)
}
if err := deleteService(*svc.ID, edge); err != nil {
if err := deleteService("gc", *svc.ID, edge); err != nil {
logrus.Errorf("error garbage collecting service: %v", err)
}
} else {
@ -108,7 +108,7 @@ func gcServiceEdgeRouterPolicies(edge *rest_management_api_client.ZitiEdgeManage
for _, serp := range listResp.Payload.Data {
if _, found := liveMap[*serp.Name]; !found {
logrus.Infof("garbage collecting, svcId='%v'", *serp.Name)
if err := deleteServiceEdgeRouterPolicy(*serp.Name, edge); err != nil {
if err := deleteServiceEdgeRouterPolicy("gc", *serp.Name, edge); err != nil {
logrus.Errorf("error garbage collecting service edge router policy: %v", err)
}
} else {
@ -135,7 +135,7 @@ func gcServicePolicies(edge *rest_management_api_client.ZitiEdgeManagement, live
if _, found := liveMap[spName]; !found {
logrus.Infof("garbage collecting, svcId='%v'", spName)
deleteFilter := fmt.Sprintf("id=\"%v\"", *sp.ID)
if err := deleteServicePolicy(deleteFilter, edge); err != nil {
if err := deleteServicePolicy("gc", deleteFilter, edge); err != nil {
logrus.Errorf("error garbage collecting service policy: %v", err)
}
} else {
@ -159,7 +159,7 @@ func gcConfigs(edge *rest_management_api_client.ZitiEdgeManagement, liveMap map[
if listResp, err := edge.Config.ListConfigs(listReq, nil); err == nil {
for _, c := range listResp.Payload.Data {
if _, found := liveMap[*c.Name]; !found {
if err := deleteConfig(*c.Name, edge); err != nil {
if err := deleteConfig("gc", *c.Name, edge); err != nil {
logrus.Errorf("error garbage collecting config: %v", err)
}
} else {

View File

@ -78,23 +78,23 @@ func (self *untunnelHandler) Handle(params tunnel.UntunnelParams, principal *res
return tunnel.NewUntunnelInternalServerError()
}
if err := deleteServiceEdgeRouterPolicy(svcName, edge); err != nil {
if err := deleteServiceEdgeRouterPolicy(senv.ZId, svcName, edge); err != nil {
logrus.Error(err)
return tunnel.NewUntunnelInternalServerError()
}
if err := deleteServicePolicyDial(svcName, edge); err != nil {
if err := deleteServicePolicyDial(senv.ZId, svcName, edge); err != nil {
logrus.Error(err)
return tunnel.NewUntunnelInternalServerError()
}
if err := deleteServicePolicyBind(svcName, edge); err != nil {
if err := deleteServicePolicyBind(senv.ZId, svcName, edge); err != nil {
logrus.Error(err)
return tunnel.NewUntunnelInternalServerError()
}
if err := deleteConfig(svcName, edge); err != nil {
if err := deleteConfig(senv.ZId, svcName, edge); err != nil {
logrus.Error(err)
return tunnel.NewTunnelInternalServerError()
}
if err := deleteService(svcZId, edge); err != nil {
if err := deleteService(senv.ZId, svcZId, edge); err != nil {
logrus.Error(err)
return tunnel.NewUntunnelInternalServerError()
}