Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add subscription id in Azure-api #5291

Merged
merged 63 commits into from
Jun 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
492397d
Subscription ID added
Jun 8, 2021
ae7cdbb
added subscription_id attr in backend
shaik80 Jun 8, 2021
97a363d
logs for stdOut and stdErr
shaik80 Jun 8, 2021
fd0b990
logs for runssmjob and runner.go job
shaik80 Jun 8, 2021
4414727
jobrunner
shaik80 Jun 8, 2021
4ff2304
jobrunner with key
shaik80 Jun 8, 2021
e0747d4
logs with future
shaik80 Jun 9, 2021
11d83f1
subscrion added to env inruuner.go file
shaik80 Jun 9, 2021
b99042d
remove logs
shaik80 Jun 9, 2021
ae065cc
error response and test cases for subscription_id is update
shaik80 Jun 15, 2021
f88735b
logs with future
shaik80 Jun 9, 2021
7d4d578
subscription_Id is optional
shaik80 Jun 16, 2021
19bf143
added test cases for subscriptionID and some comments for subscriptionID
shaik80 Jun 16, 2021
080a6e3
signOff
shaik80 Jun 16, 2021
adcb831
show subscriptiionID only if ServiceType is azure-api
shaik80 Jun 17, 2021
ce51950
review changes
shaik80 Jun 17, 2021
7aef274
resloved linting issue
shaik80 Jun 25, 2021
36d2652
lint changes
shaik80 Jun 25, 2021
48201d9
added subscription_id attr in backend
shaik80 Jun 8, 2021
d0071a0
logs with future
shaik80 Jun 9, 2021
b9ac47a
error response and test cases for subscription_id is update
shaik80 Jun 15, 2021
e2c7046
subscription_Id is optional
shaik80 Jun 16, 2021
cc8ad1c
signOff
shaik80 Jun 16, 2021
a89cdfe
protoBuf update file
shaik80 Jun 25, 2021
58c5e89
added test cases with SubscriptionID
shaik80 Jun 25, 2021
de48697
chenged input box type from text tp password
shaik80 Jun 25, 2021
10905e5
AZURE_SUBSCRIPTION_ID is equal to fake-4 (TEST CASES)
shaik80 Jun 25, 2021
043f909
Subscription ID added
Jun 8, 2021
e7c4375
added subscription_id attr in backend
shaik80 Jun 8, 2021
b8e0229
logs for stdOut and stdErr
shaik80 Jun 8, 2021
b4e7d69
logs for runssmjob and runner.go job
shaik80 Jun 8, 2021
5308e6a
jobrunner
shaik80 Jun 8, 2021
7ebc60f
jobrunner with key
shaik80 Jun 8, 2021
4dbe780
logs with future
shaik80 Jun 9, 2021
7f52b60
subscrion added to env inruuner.go file
shaik80 Jun 9, 2021
4e5ae8c
remove logs
shaik80 Jun 9, 2021
60986c0
error response and test cases for subscription_id is update
shaik80 Jun 15, 2021
6c1d6e1
logs with future
shaik80 Jun 9, 2021
2b4fbaf
subscription_Id is optional
shaik80 Jun 16, 2021
122ad6d
added test cases for subscriptionID and some comments for subscriptionID
shaik80 Jun 16, 2021
76102aa
signOff
shaik80 Jun 16, 2021
4056b49
show subscriptiionID only if ServiceType is azure-api
shaik80 Jun 17, 2021
e737894
review changes
shaik80 Jun 17, 2021
a3042a5
resloved linting issue
shaik80 Jun 25, 2021
c4857d3
lint changes
shaik80 Jun 25, 2021
3689c42
added subscription_id attr in backend
shaik80 Jun 8, 2021
f56bc32
logs with future
shaik80 Jun 9, 2021
544d353
error response and test cases for subscription_id is update
shaik80 Jun 15, 2021
b780184
subscription_Id is optional
shaik80 Jun 16, 2021
b6f5f84
signOff
shaik80 Jun 16, 2021
41c1bb8
protoBuf update file
shaik80 Jun 25, 2021
2d2944a
added test cases with SubscriptionID
shaik80 Jun 25, 2021
d017110
chenged input box type from text tp password
shaik80 Jun 25, 2021
e772e4c
AZURE_SUBSCRIPTION_ID is equal to fake-4 (TEST CASES)
shaik80 Jun 25, 2021
7204c22
Merge branch 'azure_intigration_demo' of https://github.com/chef/auto…
shaik80 Jun 27, 2021
0c31231
lint changes
shaik80 Jun 27, 2021
a646de8
error response and test cases for subscription_id is update
shaik80 Jun 15, 2021
b04cf71
subscription_Id is optional
shaik80 Jun 16, 2021
461310d
error response and test cases for subscription_id is update
shaik80 Jun 15, 2021
655a27b
subscription_Id is optional
shaik80 Jun 16, 2021
808cea4
lint changes
shaik80 Jun 27, 2021
85f17c9
Merge branch 'azure_intigration_demo' of https://github.com/chef/auto…
shaik80 Jun 28, 2021
2ac387a
removed logs
shaik80 Jun 28, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions api/external/secrets/secrets.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions api/external/secrets/secrets.proto
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ service SecretsService {
service_now: username, password
aws: AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, AWS_SESSION_TOKEN
azure: AZURE_CLIENT_ID, AZURE_CLIENT_SECRET, AZURE_TENANT_ID
azure: AZURE_SUBSCRIPTION_ID is optional
gcp: GOOGLE_CREDENTIALS_JSON

Example:
Expand Down
2 changes: 1 addition & 1 deletion api/external/secrets/secrets.swagger.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion components/automate-gateway/api/secrets.pb.swagger.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ export class IntegrationsAddComponent implements OnDestroy {
credentials: fb.group({
azure_client_id: '',
azure_client_secret: '',
azure_tenant_id: ''
azure_tenant_id: '',
azure_subscription_id: ''
})
}),
gcp: fb.group({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@
<span class="label">Tenant ID</span>
<input chefInput type="password" formControlName="azure_tenant_id" />
</label>
<label class="form-field" *ngIf="isApiServiceType()">
<span class="label">Subscription ID</span>
<input chefInput type="password" formControlName="azure_subscription_id" />
</label>
</ng-container>

</ng-container>
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,7 @@ export class IntegrationsAzureFormComponent {
const no_creds = get('no_creds', formData);
return !no_creds;
}
isApiServiceType() {
return this.formGroup.value.service_type === 'azure-api';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ export class IntegrationsEditComponent implements OnDestroy {
credentials: fb.group({
azure_client_id: '',
azure_client_secret: '',
azure_tenant_id: ''
azure_tenant_id: '',
azure_subscription_id: ''
})
}),
gcp: fb.group({
Expand Down
20 changes: 11 additions & 9 deletions components/compliance-service/inspec-agent/resolver/resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ func (r *Resolver) handleAzureApiNodes(ctx context.Context, m *manager.NodeManag
if err != nil {
return nil, fmt.Errorf("unable to fetch credential id:%s %s", m.CredentialId, err.Error())
}
clientID, clientSecret, tenantID := managers.GetAzureCreds(secret)
clientID, clientSecret, tenantID, subscriptionID := managers.GetAzureCreds(secret)

jobArray := []*types.InspecJob{}
for _, group := range nodeCollections {
Expand All @@ -192,9 +192,10 @@ func (r *Resolver) handleAzureApiNodes(ctx context.Context, m *manager.NodeManag
SubscriptionId: node.ID,
}
secrets := inspec.Secrets{
AzureClientID: clientID,
AzureClientSecret: clientSecret,
AzureTenantID: tenantID,
AzureClientID: clientID,
AzureClientSecret: clientSecret,
AzureTenantID: tenantID,
AzureSubscriptionID: subscriptionID,
}
inspecJob, err := assembleJob(job, nodeInfo, []*inspec.Secrets{&secrets}, tc)
if err != nil {
Expand Down Expand Up @@ -554,7 +555,7 @@ func (r *Resolver) handleInstanceCredentials(ctx context.Context, instanceCreds

func (r *Resolver) handleManagerNodes(ctx context.Context, m *manager.NodeManager, nodeCollections map[string]managerNodes, job *jobs.Job) ([]*types.InspecJob, error) {
jobArray := []*types.InspecJob{}
var clientID, clientSecret, tenantID string
var clientID, clientSecret, tenantID, subscriptionID string
if m.Type == "azure-vm" {
if len(m.CredentialId) == 0 {
logrus.Infof("GetAzureCreds attempting to use environment credentials")
Expand All @@ -564,7 +565,7 @@ func (r *Resolver) handleManagerNodes(ctx context.Context, m *manager.NodeManage
logrus.Errorf("Failed to get manager credentials for node manager %s: %s", m.Id, err.Error())
}
if m.Type == "azure-vm" {
clientID, clientSecret, tenantID = managers.GetAzureCreds(mgrCreds)
clientID, clientSecret, tenantID, subscriptionID = managers.GetAzureCreds(mgrCreds)
}
}
}
Expand Down Expand Up @@ -616,9 +617,10 @@ func (r *Resolver) handleManagerNodes(ctx context.Context, m *manager.NodeManage
}
if m.Type == "azure-vm" {
credsArr = append(credsArr, &inspec.Secrets{
AzureClientID: clientID,
AzureClientSecret: clientSecret,
AzureTenantID: tenantID,
AzureClientID: clientID,
AzureClientSecret: clientSecret,
AzureTenantID: tenantID,
AzureSubscriptionID: subscriptionID,
})
}
inspecJob, err := assembleJob(job, nodeDetails, credsArr, tc)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,6 @@ func (t *InspecJobTask) Run(ctx context.Context, task cereal.Task) (interface{},

cleanupKeys(job.TargetConfig.KeyFiles)
logrus.Debugf("job '%s' finished", job.JobID)

if job.NodeStatus == types.StatusRunning {
job.NodeStatus = types.StatusFailed
}
Expand Down Expand Up @@ -702,6 +701,7 @@ func cloudEnvVars(tc *inspec.TargetConfig) (map[string]string, map[string]string
envsMap["AZURE_CLIENT_ID"] = tc.AzureClientID
envsMap["AZURE_CLIENT_SECRET"] = tc.AzureClientSecret
envsMap["AZURE_TENANT_ID"] = tc.AzureTenantID
envsMap["AZURE_SUBSCRIPTION_ID"] = tc.AzureSubscriptionID
return envsMap, inputs, nil
case "gcp":
if tc.GcpCredsJson != "" {
Expand Down
3 changes: 1 addition & 2 deletions components/compliance-service/inspec/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ func Scan(paths []string, target *TargetConfig, timeout time.Duration, env map[s
}

stdOut, stdErr, err := run(args, target, timeout, env)

stdOutErr := ""
if len(stdOut) == 0 {
stdOutErr = "Empty STDOUT, we have a problem..."
Expand Down Expand Up @@ -163,7 +162,7 @@ func sanitizeEnv(env map[string]string) map[string]string {
outEnv := make(map[string]string, len(env))
for k, v := range env {
switch k {
case "AWS_SECRET_ACCESS_KEY", "AWS_SESSION_TOKEN", "AZURE_CLIENT_SECRET":
case "AWS_SECRET_ACCESS_KEY", "AWS_SESSION_TOKEN", "AZURE_CLIENT_SECRET", "AZURE_SUBSCRIPTION_ID":
outEnv[k] = "REDACTED"
default:
outEnv[k] = v
Expand Down
25 changes: 13 additions & 12 deletions components/compliance-service/inspec/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,18 +243,19 @@ type Error struct {
}

type Secrets struct {
User string `json:"user,omitempty"`
Password string `json:"password,omitempty"`
KeyFiles []string `json:"key_files,omitempty"`
SudoPassword string `json:"sudo_password,omitempty"`
SudoOptions string `json:"sudo_options,omitempty"`
AwsUser string `json:"aws_user,omitempty"`
AwsPassword string `json:"aws_password,omitempty"`
AzureClientID string `json:"azure_client_id,omitempty"`
AzureClientSecret string `json:"azure_client_secret,omitempty"`
AzureTenantID string `json:"azure_tenant_id,omitempty"`
GcpCredsJson string `json:"gcp_creds_json,omitempty"`
AwsSessionToken string `json:"aws_session_token,omitempty"`
User string `json:"user,omitempty"`
Password string `json:"password,omitempty"`
KeyFiles []string `json:"key_files,omitempty"`
SudoPassword string `json:"sudo_password,omitempty"`
SudoOptions string `json:"sudo_options,omitempty"`
AwsUser string `json:"aws_user,omitempty"`
AwsPassword string `json:"aws_password,omitempty"`
AzureClientID string `json:"azure_client_id,omitempty"`
AzureClientSecret string `json:"azure_client_secret,omitempty"`
AzureTenantID string `json:"azure_tenant_id,omitempty"`
AzureSubscriptionID string `json:"azure_subscription_id,omitempty"`
GcpCredsJson string `json:"gcp_creds_json,omitempty"`
AwsSessionToken string `json:"aws_session_token,omitempty"`
}

type TargetBaseConfig struct {
Expand Down
9 changes: 5 additions & 4 deletions components/nodemanager-service/managers/azure/azure.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,13 @@ import (
)

type Creds struct {
Token *adal.ServicePrincipalToken
TenantID string
Token *adal.ServicePrincipalToken
TenantID string
SubscriptionID string
}

// New returns a Creds struct of ServicePrincipalToken and TenantID given azure creds
func New(clientID string, clientSecret string, tenantID string) (Creds, error) {
func New(clientID string, clientSecret string, tenantID string, subscriptionID string) (Creds, error) {
if len(clientID) == 0 && len(clientSecret) == 0 && len(tenantID) == 0 {
return Creds{}, nil
}
Expand All @@ -50,7 +51,7 @@ func New(clientID string, clientSecret string, tenantID string) (Creds, error) {
return Creds{}, errors.Wrap(err, "azure - New unable to get token")
}
token.SetAutoRefresh(true)
return Creds{Token: token, TenantID: tenantID}, nil
return Creds{Token: token, TenantID: tenantID, SubscriptionID: subscriptionID}, nil
}

func getAuthorizer(token *adal.ServicePrincipalToken) autorest.Authorizer {
Expand Down
24 changes: 14 additions & 10 deletions components/nodemanager-service/managers/managers.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ func GetAWSCreds(secret *secrets.Secret) awsec2.AwsCreds {
}
}

// GetAzureCreds returns clientID, clientSecret, tenantID
func GetAzureCreds(secret *secrets.Secret) (string, string, string) {
clientID, clientSecret, tenantID := "", "", ""
// GetAzureCreds returns clientID, clientSecret, tenantID, subscriptionID
func GetAzureCreds(secret *secrets.Secret) (string, string, string, string) {
clientID, clientSecret, tenantID, subscriptionID := "", "", "", ""
if secret != nil {
for _, item := range secret.Data {
if item.Key == "AZURE_CLIENT_ID" {
Expand All @@ -68,12 +68,16 @@ func GetAzureCreds(secret *secrets.Secret) (string, string, string) {
if item.Key == "AZURE_TENANT_ID" {
tenantID = item.Value
}
if item.Key == "AZURE_SUBSCRIPTION_ID" {
subscriptionID = item.Value
}
}
}
if len(clientID) == 0 || len(clientSecret) == 0 || len(tenantID) == 0 {
logrus.Infof("GetAzureCreds attempting to use environment credentials")
}
return clientID, clientSecret, tenantID

return clientID, clientSecret, tenantID, subscriptionID
}

func GetAWSManagerFromCredential(ctx context.Context, credential string, db *pgdb.DB, secretsClient secrets.SecretsServiceClient) (myaws *awsec2.AwsCreds, err error) {
Expand All @@ -91,16 +95,16 @@ func GetAWSManagerFromCredential(ctx context.Context, credential string, db *pgd
}

func GetAzureManagerFromCredential(ctx context.Context, credential string, db *pgdb.DB, secretsClient secrets.SecretsServiceClient) (myaws *azure.Creds, err error) {
var clientID, clientSecret, tenantID string
var clientID, clientSecret, tenantID, subscriptionID string
if len(credential) > 0 {
secret, err := secretsClient.Read(ctx, &secrets.Id{Id: credential})
if err != nil {
return nil, errors.Wrapf(err, "Could not find secret with id %s", credential)
}

clientID, clientSecret, tenantID = GetAzureCreds(secret)
clientID, clientSecret, tenantID, subscriptionID = GetAzureCreds(secret)
}
creds, err := azure.New(clientID, clientSecret, tenantID)
creds, err := azure.New(clientID, clientSecret, tenantID, subscriptionID)
if err != nil {
return nil, errors.Wrap(err, "GetAzureManagerFromCredential unable to initialize connection to azure api")
}
Expand Down Expand Up @@ -144,8 +148,8 @@ func GetAzureManagerFromID(ctx context.Context, id string, db *pgdb.DB, secretsC
return nil, errors.Wrapf(err, "Could not find secret with manager id %s", id)
}

clientID, clientSecret, tenantID := GetAzureCreds(azureSecret)
creds, err := azure.New(clientID, clientSecret, tenantID)
clientID, clientSecret, tenantID, subscriptionID := GetAzureCreds(azureSecret)
creds, err := azure.New(clientID, clientSecret, tenantID, subscriptionID)
if err != nil {
return nil, errors.Wrap(err, "GetAzureManagerFromID unable to initialize connection to azure api")
}
Expand Down Expand Up @@ -263,7 +267,7 @@ func SendRemoteExecutionJob(ctx context.Context, job *types.InspecJob, script st
s := awsec2.NewSSM()
return s.SendSSMJob(ctx, job, script, scriptType)
case inspec.BackendAZ, inspec.BackendAZWindows:
creds, err := azure.New(job.TargetConfig.AzureClientID, job.TargetConfig.AzureClientSecret, job.TargetConfig.AzureTenantID)
creds, err := azure.New(job.TargetConfig.AzureClientID, job.TargetConfig.AzureClientSecret, job.TargetConfig.AzureTenantID, job.TargetConfig.AzureSubscriptionID)
if err != nil {
return errors.Wrap(err, "SendRemoteExecutionJob unable to initialize connection to azure api")
}
Expand Down
32 changes: 32 additions & 0 deletions components/nodemanager-service/managers/managers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,35 @@ func TestGetAWSCredsSetsRegionWhenProvided(t *testing.T) {
Region: "user-provided-region",
}, creds)
}

//AZURE
func TestAzureCredsWithOutSubscriptionID(t *testing.T) {
secret := &secrets.Secret{
Data: []*query.Kv{
{Key: "AZURE_CLIENT_ID", Value: "fake-1"},
{Key: "AZURE_CLIENT_SECRET", Value: "fake-2"},
{Key: "AZURE_TENANT_ID", Value: "fake-3"},
},
}
clientID, clientSecret, tenantID, subscriptionID := GetAzureCreds(secret)
assert.Equal(t, "fake-1", clientID)
assert.Equal(t, "fake-2", clientSecret)
assert.Equal(t, "fake-3", tenantID)
assert.Equal(t, "", subscriptionID)
}

func TestAzureCredsWithSubscriptionID(t *testing.T) {
secret := &secrets.Secret{
Data: []*query.Kv{
{Key: "AZURE_CLIENT_ID", Value: "fake-1"},
{Key: "AZURE_CLIENT_SECRET", Value: "fake-2"},
{Key: "AZURE_TENANT_ID", Value: "fake-3"},
{Key: "AZURE_SUBSCRIPTION_ID", Value: "fake-4"},
},
}
clientID, clientSecret, tenantID, subscriptionID := GetAzureCreds(secret)
assert.Equal(t, "fake-1", clientID)
assert.Equal(t, "fake-2", clientSecret)
assert.Equal(t, "fake-3", tenantID)
assert.Equal(t, "fake-4", subscriptionID)
}