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

[CIS Azure] Asset inventory / fetchers #1250

Closed
2 tasks
jeniawhite opened this issue Aug 17, 2023 · 0 comments · Fixed by #1310
Closed
2 tasks

[CIS Azure] Asset inventory / fetchers #1250

jeniawhite opened this issue Aug 17, 2023 · 0 comments · Fixed by #1310
Assignees
Labels

Comments

@jeniawhite
Copy link
Contributor

jeniawhite commented Aug 17, 2023

Motivation
In order to fetch the resources we have multiple solution paths:

  • Write fetchers for every resource type
  • Utilize Azure resource graph capabilities

The focus is to have something similar to asset inventory and avoid writing fetchers.
This is why I've focused on the ARG and implemented a small POC in order to see if it is a viable option.

// Licensed to Elasticsearch B.V. under one or more contributor
// license agreements. See the NOTICE file distributed with
// this work for additional information regarding copyright
// ownership. Elasticsearch B.V. licenses this file to you under
// the Apache License, Version 2.0 (the "License"); you may
// not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied.  See the License for the
// specific language governing permissions and limitations
// under the License.

package main

import (
	"context"
	"fmt"
	"log"

	"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
	"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
	"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resourcegraph/armresourcegraph"
)

func main() {
	cred, err := azidentity.NewDefaultAzureCredential(nil)
	if err != nil {
		log.Fatalf("failed to obtain a credential: %v", err)
	}
	ctx := context.Background()
	clientFactory, err := armresourcegraph.NewClientFactory(cred, nil)
	if err != nil {
		log.Fatalf("failed to create client: %v", err)
	}
	res, err := clientFactory.NewClient().Resources(ctx, armresourcegraph.QueryRequest{
		// Query: to.Ptr("Resources | where type =~ 'Microsoft.Storage/StorageAccounts' | limit 1"),
		Query: to.Ptr("Resources"),
		Subscriptions: []*string{
			to.Ptr("SUB_ID")},
	}, nil)
	if err != nil {
		log.Fatalf("failed to finish the request: %v", err)
	}
	fmt.Printf("%v", res.Data)
}

Running this on my subscription resulted in a response with all of the resources inside the subscription.
There is also an option to run the queries on management groups.

Definition of done
What needs to be completed at the end of this task

  • Implement fetching of resources using ARG with pagination
  • Support management groups
@jeniawhite jeniawhite added Team:Cloud Security Cloud Security team related CIS Azure labels Aug 17, 2023
@oren-zohar oren-zohar changed the title [CIS Azure] Asset inventory / fetchers [CIS Azure] Asset inventory/fetchers Aug 21, 2023
@oren-zohar oren-zohar changed the title [CIS Azure] Asset inventory/fetchers [CIS Azure] Asset inventory / fetchers Aug 21, 2023
@jeniawhite jeniawhite self-assigned this Sep 3, 2023
@oren-zohar oren-zohar assigned orestisfl and unassigned jeniawhite Sep 11, 2023
@orestisfl orestisfl assigned jeniawhite and unassigned orestisfl Sep 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants