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

BED-3828: Audit bare channel writes #61

Merged
merged 9 commits into from
Nov 8, 2023
2 changes: 1 addition & 1 deletion client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func NewClient(config config.Config) (AzureClient, error) {
}
}

func initClientViaRM(msgraph, resourceManager rest.RestClient, tid interface{}) (AzureClient, error) {
func initClientViaRM(msgraph, resourceManager rest.RestClient, tid any) (AzureClient, error) {
client := &azureClient{
msgraph: msgraph,
resourceManager: resourceManager,
Expand Down
130 changes: 65 additions & 65 deletions client/mocks/client.go

Large diffs are not rendered by default.

18 changes: 9 additions & 9 deletions client/rest/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ import (

type RestClient interface {
Authenticate() error
Delete(ctx context.Context, path string, body interface{}, params, headers map[string]string) (*http.Response, error)
Delete(ctx context.Context, path string, body any, params, headers map[string]string) (*http.Response, error)
Get(ctx context.Context, path string, params, headers map[string]string) (*http.Response, error)
Patch(ctx context.Context, path string, body interface{}, params, headers map[string]string) (*http.Response, error)
Post(ctx context.Context, path string, body interface{}, params, headers map[string]string) (*http.Response, error)
Put(ctx context.Context, path string, body interface{}, params, headers map[string]string) (*http.Response, error)
Patch(ctx context.Context, path string, body any, params, headers map[string]string) (*http.Response, error)
Post(ctx context.Context, path string, body any, params, headers map[string]string) (*http.Response, error)
Put(ctx context.Context, path string, body any, params, headers map[string]string) (*http.Response, error)
Send(req *http.Request) (*http.Response, error)
CloseIdleConnections()
}
Expand Down Expand Up @@ -155,7 +155,7 @@ func (s *restClient) Authenticate() error {
}
}

func (s *restClient) Delete(ctx context.Context, path string, body interface{}, params, headers map[string]string) (*http.Response, error) {
func (s *restClient) Delete(ctx context.Context, path string, body any, params, headers map[string]string) (*http.Response, error) {
endpoint := s.api.ResolveReference(&url.URL{Path: path})
if req, err := NewRequest(ctx, http.MethodDelete, endpoint, body, params, headers); err != nil {
return nil, err
Expand All @@ -173,7 +173,7 @@ func (s *restClient) Get(ctx context.Context, path string, params, headers map[s
}
}

func (s *restClient) Patch(ctx context.Context, path string, body interface{}, params, headers map[string]string) (*http.Response, error) {
func (s *restClient) Patch(ctx context.Context, path string, body any, params, headers map[string]string) (*http.Response, error) {
endpoint := s.api.ResolveReference(&url.URL{Path: path})
if req, err := NewRequest(ctx, http.MethodPatch, endpoint, body, params, headers); err != nil {
return nil, err
Expand All @@ -182,7 +182,7 @@ func (s *restClient) Patch(ctx context.Context, path string, body interface{}, p
}
}

func (s *restClient) Post(ctx context.Context, path string, body interface{}, params, headers map[string]string) (*http.Response, error) {
func (s *restClient) Post(ctx context.Context, path string, body any, params, headers map[string]string) (*http.Response, error) {
endpoint := s.api.ResolveReference(&url.URL{Path: path})
if req, err := NewRequest(ctx, http.MethodPost, endpoint, body, params, headers); err != nil {
return nil, err
Expand All @@ -191,7 +191,7 @@ func (s *restClient) Post(ctx context.Context, path string, body interface{}, pa
}
}

func (s *restClient) Put(ctx context.Context, path string, body interface{}, params, headers map[string]string) (*http.Response, error) {
func (s *restClient) Put(ctx context.Context, path string, body any, params, headers map[string]string) (*http.Response, error) {
endpoint := s.api.ResolveReference(&url.URL{Path: path})
if req, err := NewRequest(ctx, http.MethodPost, endpoint, body, params, headers); err != nil {
return nil, err
Expand Down Expand Up @@ -275,7 +275,7 @@ func (s *restClient) send(req *http.Request) (*http.Response, error) {
continue
} else {
// Not a status code that warrants a retry
var errRes map[string]interface{}
var errRes map[string]any
if err := Decode(res.Body, &errRes); err != nil {
return nil, fmt.Errorf("malformed error response, status code: %d", res.StatusCode)
} else {
Expand Down
2 changes: 1 addition & 1 deletion client/rest/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func NewRequest(
ctx context.Context,
verb string,
endpoint *url.URL,
body interface{},
body any,
params map[string]string,
headers map[string]string,
) (*http.Request, error) {
Expand Down
20 changes: 10 additions & 10 deletions client/rest/mocks/client.go

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

10 changes: 5 additions & 5 deletions client/rest/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import (
"github.com/youmark/pkcs8"
)

func Decode(body io.ReadCloser, v interface{}) error {
func Decode(body io.ReadCloser, v any) error {
defer body.Close()
defer io.ReadAll(body) // must read all; streaming to the json decoder does not read to EOF making the connection unavailable for reuse
return json.NewDecoder(body).Decode(v)
Expand All @@ -59,7 +59,7 @@ func NewClientAssertion(tokenUrl string, clientId string, clientCert string, sig
IssuedAt: iat.Unix(),
})

token.Header = map[string]interface{}{
token.Header = map[string]any{
"alg": "RS256",
"typ": "JWT",
"x5t": thumbprint,
Expand All @@ -73,9 +73,9 @@ func NewClientAssertion(tokenUrl string, clientId string, clientCert string, sig
}
}

func ParseBody(accessToken string) (map[string]interface{}, error) {
func ParseBody(accessToken string) (map[string]any, error) {
var (
body = make(map[string]interface{})
body = make(map[string]any)
parts = strings.Split(accessToken, ".")
)

Expand All @@ -100,7 +100,7 @@ func ParseAud(accessToken string) (string, error) {
}
}

func parseRSAPrivateKey(signingKey string, password string) (interface{}, error) {
func parseRSAPrivateKey(signingKey string, password string) (any, error) {
if decodedBlock, _ := pem.Decode([]byte(signingKey)); decodedBlock == nil {
return nil, fmt.Errorf("Unable to decode private key")
} else if key, _, err := pkcs8.ParsePrivateKey(decodedBlock.Bytes, []byte(password)); err != nil {
Expand Down
24 changes: 12 additions & 12 deletions cmd/list-azure-ad.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,23 +59,23 @@ func listAzureADCmdImpl(cmd *cobra.Command, args []string) {
log.Info("collection completed", "duration", duration.String())
}

func listAllAD(ctx context.Context, client client.AzureClient) <-chan interface{} {
func listAllAD(ctx context.Context, client client.AzureClient) <-chan any {
var (
devices = make(chan interface{})
devices2 = make(chan interface{})
devices = make(chan any)
devices2 = make(chan any)

groups = make(chan interface{})
groups2 = make(chan interface{})
groups3 = make(chan interface{})
groups = make(chan any)
groups2 = make(chan any)
groups3 = make(chan any)

roles = make(chan interface{})
roles2 = make(chan interface{})
roles = make(chan any)
roles2 = make(chan any)

servicePrincipals = make(chan interface{})
servicePrincipals2 = make(chan interface{})
servicePrincipals3 = make(chan interface{})
servicePrincipals = make(chan any)
servicePrincipals2 = make(chan any)
servicePrincipals3 = make(chan any)

tenants = make(chan interface{})
tenants = make(chan any)
)

// Enumerate Apps, AppOwners and AppMembers
Expand Down
80 changes: 40 additions & 40 deletions cmd/list-azure-rm.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,65 +61,65 @@ func listAzureRMCmdImpl(cmd *cobra.Command, args []string) {
log.Info("collection completed", "duration", duration.String())
}

func listAllRM(ctx context.Context, client client.AzureClient) <-chan interface{} {
func listAllRM(ctx context.Context, client client.AzureClient) <-chan any {
var (
functionApps = make(chan interface{})
functionApps2 = make(chan interface{})
functionApps = make(chan any)
functionApps2 = make(chan any)

webApps = make(chan interface{})
webApps2 = make(chan interface{})
webApps = make(chan any)
webApps2 = make(chan any)

automationAccounts = make(chan interface{})
automationAccounts2 = make(chan interface{})
automationAccounts = make(chan any)
automationAccounts2 = make(chan any)

containerRegistries = make(chan interface{})
containerRegistries2 = make(chan interface{})
containerRegistries = make(chan any)
containerRegistries2 = make(chan any)

logicApps = make(chan interface{})
logicApps2 = make(chan interface{})
logicApps = make(chan any)
logicApps2 = make(chan any)

managedClusters = make(chan interface{})
managedClusters2 = make(chan interface{})
managedClusters = make(chan any)
managedClusters2 = make(chan any)

vmScaleSets = make(chan interface{})
vmScaleSets2 = make(chan interface{})
vmScaleSets = make(chan any)
vmScaleSets2 = make(chan any)

keyVaults = make(chan interface{})
keyVaults2 = make(chan interface{})
keyVaults3 = make(chan interface{})
keyVaults = make(chan any)
keyVaults2 = make(chan any)
keyVaults3 = make(chan any)
keyVaultRoleAssignments1 = make(chan azureWrapper[models.KeyVaultRoleAssignments])
keyVaultRoleAssignments2 = make(chan azureWrapper[models.KeyVaultRoleAssignments])
keyVaultRoleAssignments3 = make(chan azureWrapper[models.KeyVaultRoleAssignments])
keyVaultRoleAssignments4 = make(chan azureWrapper[models.KeyVaultRoleAssignments])

mgmtGroups = make(chan interface{})
mgmtGroups2 = make(chan interface{})
mgmtGroups3 = make(chan interface{})
mgmtGroups = make(chan any)
mgmtGroups2 = make(chan any)
mgmtGroups3 = make(chan any)
mgmtGroupRoleAssignments1 = make(chan azureWrapper[models.ManagementGroupRoleAssignments])
mgmtGroupRoleAssignments2 = make(chan azureWrapper[models.ManagementGroupRoleAssignments])

resourceGroups = make(chan interface{})
resourceGroups2 = make(chan interface{})
resourceGroups = make(chan any)
resourceGroups2 = make(chan any)
resourceGroupRoleAssignments1 = make(chan azureWrapper[models.ResourceGroupRoleAssignments])
resourceGroupRoleAssignments2 = make(chan azureWrapper[models.ResourceGroupRoleAssignments])

subscriptions = make(chan interface{})
subscriptions2 = make(chan interface{})
subscriptions3 = make(chan interface{})
subscriptions4 = make(chan interface{})
subscriptions5 = make(chan interface{})
subscriptions6 = make(chan interface{})
subscriptions7 = make(chan interface{})
subscriptions8 = make(chan interface{})
subscriptions9 = make(chan interface{})
subscriptions10 = make(chan interface{})
subscriptions11 = make(chan interface{})
subscriptions12 = make(chan interface{})
subscriptionRoleAssignments1 = make(chan interface{})
subscriptionRoleAssignments2 = make(chan interface{})

virtualMachines = make(chan interface{})
virtualMachines2 = make(chan interface{})
subscriptions = make(chan any)
subscriptions2 = make(chan any)
subscriptions3 = make(chan any)
subscriptions4 = make(chan any)
subscriptions5 = make(chan any)
subscriptions6 = make(chan any)
subscriptions7 = make(chan any)
subscriptions8 = make(chan any)
subscriptions9 = make(chan any)
subscriptions10 = make(chan any)
subscriptions11 = make(chan any)
subscriptions12 = make(chan any)
subscriptionRoleAssignments1 = make(chan any)
subscriptionRoleAssignments2 = make(chan any)

virtualMachines = make(chan any)
virtualMachines2 = make(chan any)
virtualMachineRoleAssignments1 = make(chan azureWrapper[models.VirtualMachineRoleAssignments])
virtualMachineRoleAssignments2 = make(chan azureWrapper[models.VirtualMachineRoleAssignments])
virtualMachineRoleAssignments3 = make(chan azureWrapper[models.VirtualMachineRoleAssignments])
Expand Down
2 changes: 1 addition & 1 deletion cmd/list-device-owners_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func TestListDeviceOwners(t *testing.T) {

mockClient := mocks.NewMockAzureClient(ctrl)

mockDevicesChannel := make(chan interface{})
mockDevicesChannel := make(chan any)
mockDeviceOwnerChannel := make(chan azure.DeviceRegisteredOwnerResult)
mockDeviceOwnerChannel2 := make(chan azure.DeviceRegisteredOwnerResult)

Expand Down
2 changes: 1 addition & 1 deletion cmd/list-group-members_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func TestListGroupMembers(t *testing.T) {

mockClient := mocks.NewMockAzureClient(ctrl)

mockGroupsChannel := make(chan interface{})
mockGroupsChannel := make(chan any)
mockGroupMemberChannel := make(chan azure.MemberObjectResult)
mockGroupMemberChannel2 := make(chan azure.MemberObjectResult)

Expand Down
2 changes: 1 addition & 1 deletion cmd/list-group-owners_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func TestListGroupOwners(t *testing.T) {

mockClient := mocks.NewMockAzureClient(ctrl)

mockGroupsChannel := make(chan interface{})
mockGroupsChannel := make(chan any)
mockGroupOwnerChannel := make(chan azure.GroupOwnerResult)
mockGroupOwnerChannel2 := make(chan azure.GroupOwnerResult)

Expand Down
2 changes: 1 addition & 1 deletion cmd/list-key-vault-access-policies_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func TestListKeyVaultAccessPolicies(t *testing.T) {

mockClient := mocks.NewMockAzureClient(ctrl)

mockKeyVaultsChannel := make(chan interface{})
mockKeyVaultsChannel := make(chan any)
mockTenant := azure.Tenant{}
mockClient.EXPECT().TenantInfo().Return(mockTenant).AnyTimes()
channel := listKeyVaultAccessPolicies(ctx, mockClient, mockKeyVaultsChannel, nil)
Expand Down
2 changes: 1 addition & 1 deletion cmd/list-key-vault-role-assignments.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func listKeyVaultRoleAssignmentsCmdImpl(cmd *cobra.Command, args []string) {
log.Info("collection completed", "duration", duration.String())
}

func listKeyVaultRoleAssignments(ctx context.Context, client client.AzureClient, keyVaults <-chan interface{}) <-chan azureWrapper[models.KeyVaultRoleAssignments] {
func listKeyVaultRoleAssignments(ctx context.Context, client client.AzureClient, keyVaults <-chan any) <-chan azureWrapper[models.KeyVaultRoleAssignments] {
var (
out = make(chan azureWrapper[models.KeyVaultRoleAssignments])
ids = make(chan string)
Expand Down
2 changes: 1 addition & 1 deletion cmd/list-key-vault-role-assignments_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func TestListKeyVaultRoleAssignments(t *testing.T) {

mockClient := mocks.NewMockAzureClient(ctrl)

mockKeyVaultsChannel := make(chan interface{})
mockKeyVaultsChannel := make(chan any)
mockKeyVaultRoleAssignmentChannel := make(chan azure.RoleAssignmentResult)
mockKeyVaultRoleAssignmentChannel2 := make(chan azure.RoleAssignmentResult)

Expand Down
Loading
Loading