Skip to content

Commit

Permalink
⭐️ add api examples
Browse files Browse the repository at this point in the history
  • Loading branch information
chris-rock committed May 29, 2024
1 parent e1afc7f commit 8f5aa1e
Show file tree
Hide file tree
Showing 14 changed files with 460 additions and 0 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Welcome to our comprehensive security scanning repository! In our ongoing effort
- [Scanning an AWS EC2 Instance with cnspec using EC2 Instance Connect](#scanning-an-aws-ec2-instance-with-cnspec-using-ec2-instance-connect)
- [GitHub](#github)
- [Performing CIS GitHub Supply Chain Benchmark with cnspec](#performing-cis-github-supply-chain-benchmark-with-cnspec)
- [GraphQL API Examples](#graphql-api-examples)
- [Hack Lab](#hack-lab)
- [Demonstrating Container Escape in Kubernetes](#demonstrating-container-escape-in-kubernetes)
- [Playing with AWS EC2 Instances](#playing-with-aws-ec2-instances)
Expand Down Expand Up @@ -72,6 +73,10 @@ This guide provides an example on how to execute the CIS (Center for Internet Se

- [Instructions](./github/cis-supply-chain/)

## GraphQL API Examples

The [examples](./graphql-api) demonstrate how to query and interact with the Mondoo Platform using GraphQL.

Check failure on line 78 in README.md

View workflow job for this annotation

GitHub Actions / Run spell check

` the Mondoo Platform` matches a line_forbidden.patterns entry: `\sthe Mondoo Platform\b`. (forbidden-pattern)

## Hack Lab

The Hack Lab is a collection of vulnerable systems that can be used to learn and practice security concepts. The Hack Lab is a great way to get started with security scanning and learn how to use `cnspec` and `cnquery` to identify and resolve security issues.
Expand Down
1 change: 1 addition & 0 deletions graphql-api/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.env
35 changes: 35 additions & 0 deletions graphql-api/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Mondoo GraphQL API Samples

This repository contains sample queries for the Mondoo GraphQL API. The queries are written in GraphQL and can be executed using the [Bruno](https://docs.usebruno.com/).

## Getting Started

- Clone this repository
- Install Bruno
- Setup .env file with your Mondoo API key


## API Key

To get started with the Mondoo API, you need to create an API key. You can create an API key in the Mondoo console. Then create a `.env` file in the root of the repository with the following content:

```
MONDOO_API_TOKEN=your-api-key
MONDOO_ENDPOINT=us.api.mondoo.com
SPACE_MRN=//captain.api.mondoo.app/spaces/mystifying-jennings-299629
ORG_MRN=//captain.api.mondoo.app/organizations/lunalectric
```

> NOTE: While not technically required, it is recommended to use a organization API token with editor permissions to sure all samples work.
## CLI

Follow the installation instructions[https://docs.usebruno.com/bru-cli/overview].

```
bru run search/search.bru --env Mondoo

Check failure on line 30 in graphql-api/README.md

View workflow job for this annotation

GitHub Actions / Run spell check

`bru` is not a recognized word. (unrecognized-spelling)

Check failure on line 30 in graphql-api/README.md

View workflow job for this annotation

GitHub Actions / Run spell check

`bru` is not a recognized word. (unrecognized-spelling)
```

## APP

Follow the installation instructions[https://www.usebruno.com/downloads]. Then you open the collection and run the queries.
40 changes: 40 additions & 0 deletions graphql-api/asset_inventory/list_assets_in_space.bru
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
meta {
name: list_assets_in_space
type: graphql
seq: 1
}

post {
url: https://{{endpoint}}/query
body: graphql
auth: bearer
}

auth:bearer {
token: {{MONDOO_API_TOKEN}}
}

body:graphql {
query Assets {
assets(spaceMrn: "{{spaceMrn}}") {
totalCount
edges {
cursor
node {
id
mrn
state
name
updatedAt
referenceIDs
asset_type
score {
grade
value
}
}
}
}
}

}
9 changes: 9 additions & 0 deletions graphql-api/bruno.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"version": "1",
"name": "Mondoo GraphQL API Requests",
"type": "collection",
"ignore": [
"node_modules",
".git"
]
}
6 changes: 6 additions & 0 deletions graphql-api/environments/Mondoo.bru
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
vars {
endpoint: {{process.env.MONDOO_ENDPOINT}}
spaceMrn: {{process.env.SPACE_MRN}}
orgMrn: {{process.env.ORG_MRN}}
MONDOO_API_TOKEN: {{process.env.MONDOO_API_TOKEN}}
}
38 changes: 38 additions & 0 deletions graphql-api/organization/list_members.bru
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
meta {
name: list_members
type: graphql
seq: 2
}

post {
url: https://{{endpoint}}/query
body: graphql
auth: bearer
}

auth:bearer {
token: {{MONDOO_API_TOKEN}}
}

body:graphql {
query LoadOrganizationMembers {
organization(mrn: "{{orgMrn}}") {
id
mrn
members {
edges {
node {
user {
email
name
}
roles {
title
}
}
}
}
}
}

}
86 changes: 86 additions & 0 deletions graphql-api/organization/list_service_accounts.bru
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
meta {
name: list_service_accounts
type: graphql
seq: 3
}

post {
url: https://{{endpoint}}/query
body: graphql
auth: bearer
}

auth:bearer {
token: {{MONDOO_API_TOKEN}}
}

body:graphql {
# To list all service accounts, the API Token needs Editor permissions
query ServiceAccounts(
$scopeMrn: String
$first: Int
$after: String
$query: String
$queryTerms: [String!]
$orderBy: ServiceAccountOrder
) {
serviceAccounts(
scopeMrn: $scopeMrn
first: $first
after: $after
query: $query
queryTerms: $queryTerms
orderBy: $orderBy
) {
...ServiceAccountFields
__typename
}
}
fragment ServiceAccountFields on ServiceAccountConnection {
totalCount
edges {
cursor
node {
id
mrn
name
description
roles {
mrn
title
__typename
}
createdAt
lastUsed
labels {
key
value
__typename
}
creator {
mrn
email
service
__typename
}
notes
__typename
}
__typename
}
pageInfo {
startCursor
endCursor
hasNextPage
__typename
}
__typename
}

}

body:graphql:vars {
{
"scopeMrn": "{{spaceMrn}}"
}
}
29 changes: 29 additions & 0 deletions graphql-api/organization/list_spaces.bru
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
meta {
name: list_spaces
type: graphql
seq: 1
}

post {
url: https://{{endpoint}}/query
body: graphql
auth: bearer
}

auth:bearer {
token: {{MONDOO_API_TOKEN}}
}

body:graphql {
query OrganizationOverview {
organizationOverview(
input: { organizationMrn: "{{orgMrn}}" }
) {
organizationMrn
spacesOverview {
spaceMrn
spaceName
}
}
}
}
28 changes: 28 additions & 0 deletions graphql-api/policies_querypacks/enable_policy.bru
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
meta {
name: enable_policy
type: graphql
seq: 2
}

post {
url: https://{{endpoint}}/query
body: graphql
auth: bearer
}

auth:bearer {
token: {{MONDOO_API_TOKEN}}
}

body:graphql {
mutation {
assignPolicy(
input: {
assetMrn: "{{spaceMrn}}"
policyMrn: "//policy.api.mondoo.app/policies/mondoo-dns-security"
action: ACTIVE
}
)
}

}
51 changes: 51 additions & 0 deletions graphql-api/policies_querypacks/list_active_policies.bru
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
meta {
name: list_active_policies
type: graphql
seq: 4
}

post {
url: https://{{endpoint}}/query
body: graphql
auth: bearer
}

auth:bearer {
token: {{MONDOO_API_TOKEN}}
}

body:graphql {
query SpaceReport($input: SpaceReportInput!) {
spaceReport(input: $input) {
... on SpaceReport {
spaceMrn
policyReportSummaries {
totalCount
edges {
cursor
node {
policy {
mrn
name
assigned
action
version
isPublic
createdAt
updatedAt
}
}
}
}
}
}
}
}

body:graphql:vars {
{
"input" : {
"spaceMrn" : "{{spaceMrn}}"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
meta {
name: list_available_policies_query_packs
type: graphql
seq: 3
}

post {
url: https://{{endpoint}}/query
body: graphql
auth: bearer
}

auth:bearer {
token: {{MONDOO_API_TOKEN}}
}

body:graphql {
{
content(
input: { scopeMrn: "{{spaceMrn}}", catalogType: ALL, assignedOnly: true }
) {
totalCount
edges {
node {
__typename
... on Policy {
name
}
}
}
}
}

}
Loading

0 comments on commit 8f5aa1e

Please sign in to comment.