Query and Provision Cloud Infrastructure using an extensible SQL based grammar

Platforms Go License Lines
InfraQL

Deploy, Manage and Query Cloud Infrastructure using SQL

[Documentation] [Developer Guide]

Cloud infrastructure coding using SQL

InfraQL allows you to create, modify and query the state of services and resources across all three major public cloud providers (Google, AWS and Azure) using a common, widely known DSL...SQL.


Its as easy as...

use google; SELECT * FROM compute.instance WHERE zone = 'australia-southeast1-b' AND project = 'my-project' ;

Design

infraql generalizes the idea of infrastructure / computing reources into a provider, service, resource heirarchy that can be queried with SQL semantics, plus some imperative operations which are not canonical SQL. Potentially any infrastructure: computing, orchestration, storage, SAAS, PAAS offerings etc can be managed with infraql, athough the primary driver is cloud infrastructure management. Multi-provider queries are to be a first class citizen in infraql.

Considering query execution in a bottom-up manner from backend execution to frontend source code processing, the strategic design for infraql is:

  • Backend Execution of queries through Primitive interfaces that encapsulate access and mutation operations against arbitrary APIs. Primitives may act on any particular API, eg: http, SDK, IPC, specific wire protocol. Potentially variegated (eg: part http API, part SDK).
  • A Plan object includes a DAG of Primitives. Plans may be optimized and cached a la vitess. Logically, the Plan, once initialized, is matured in the following sequential phases:
    1. Intermediate Code Generation; for now no formal language is defined. Simply objects and function pointers of infraql, encapsulated in Primitives.
    2. Code Optimization; parallelization of independent operations, removal of redundant operations.
    3. Code Generation; final calls against whatever backend, eg http API.
  • Semantic Analysis of queries is a phase that accepts an AST as input and:
    • creates a symbol table.
    • analyzes provider heirarchies and API(s) required to complete the query. Typically these would be sourced by downloading and cacheing provider discovery documents.
    • performs type checking, scope (label) analysis.
    • creates a Planbuilder object and decorates it during analysis.
    • may generate some primitives.
    • generates, at the very least, a Plan stub.
  • Lexical and Syntax analysis; using the machinery from Vitess, which is a lex / yacc style grammar, processed with golang libraries to emulate lex and yacc. The sqlparser module, originally from vitess contains the implementation. The output is an AST.

The semantic analysis and latter phases are sensitive to the type and structure of provider backends.

infraql supports specific API versions for providers, API upgrades may require infraql reversioning.


Providers

Starting off with Google. Other providers to follow.


Build

With cmake:

cd build
cmake ..
cmake --build .

Executable build/infraql will be created.

Run

./build/infraql --help

Examples

./infraql exec "show extended services from google where title = 'Service Directory API';"

More examples in /examples.md.


Developers

/developer_guide.md.

Testing

/test/README.md.

Acknowledgements

Forks of the following support our work:

We gratefully acknowledge these pieces of work.

License

See /LICENSE

Comments
  • [FEATURE] Basic JSON Parsing Functions for Nested Properties

    [FEATURE] Basic JSON Parsing Functions for Nested Properties

    CLOSED refer to https://github.com/infraql/infraql-original/issues/196

    Feature Description Implement support to query nested or repeated fields in API responses, based upon the JSON parsing and utility functions available in MySQL

    A basic subset of the available functions to be implemented include:

    • JSON_LENGTH(<object or array field>[, path]) returns number of keys in an object or number of elements in an array
    • JSON_KEYS(<object field>[, path]) returns a comma delimited list of keys, as ["key1", "key2", etc], this is a valid array object if returned to json output
    • JSON_CONTAINS(<object or array field>, candidate[, path]) returns true or false if the object contains a value equal to the candidate, or an element equal to the candidate in an array
    • JSON_EXTRACT(<object or array field>, path[, path] ...) returns the path or element specified from an array or object field
    • JSON_PRETTY(json_val) expands pretty prints JSON in a cell (over multiple lines)
  • [FEATURE] Add support for column aliases

    [FEATURE] Add support for column aliases

    Feature Description Add support to give output columns aliases, this is supported by the Vitess parser but not implemented as yet

    The following example illustrates the desired behaviour:

    InfraQL* >>select id as fred from compute.networks where project = 'gcp-networking-intro';
    |---------------------|
    |         FRED        |
    |---------------------|
    | 1050180395817469648 |
    |---------------------|
    | 3584517666602292862 |
    |---------------------|
    | 5689506324057616817 |
    |---------------------|
    

    Aliases can be enclosed in single or double quotes, and can include embedded spaces (if embedded spaces are used, the alias must be enclosed with quotes)

  • [FEATURE] Documentation for Custom Providers

    [FEATURE] Documentation for Custom Providers

    Hello, I came across this project and was interested in trying it out as it claims to be provider agnostic, however all of the documentation uses Google Compute Platform as a provider, and I am not interested in using GCP at all, I want to be able to use InfraQL with smaller cloud providers like DigitalOcean or Linode.

    So this an issue asking for documentation on how to use InfraQL with different providers, and how I as user can add more providers.

  • [FEATURE] readplan

    [FEATURE] readplan

    Feature Description Build a command line application in Golang called readplan, which takes one mandatory argument operation and one optional argument resource

    Example(s) Valid combinations are: readplan show readplan select <resource_type> The show command reads the attached Terraform state file (terraform.tfstate), and returns a flattened json object with a list of all resources in the state file based upon the type value, for instance: [ “aws_s3_bucket_policy”, “aws_s3_bucket”, ... ]

    Possible Approaches or Libraries to Consider The Select command, for a resource such as readplan select “aws_s3_bucket” Would return a flattened json response including the name and provider values for the resource as well as each key and its value from the instances list, for instance:

    [
      {
        "name": "ext_stage",
        "provider": "provider.aws",
        "schema_version": 0,
        "attributes": {
          "acceleration_status": "",
          "acl": "private",
          "arn": "arn:aws:s3:::snowpipe-stage",
          "bucket": "snowpipe-stage",
          "bucket_domain_name": "snowpipe-stage.s3.amazonaws.com",
    
          "bucket_prefix": null,
          "bucket_regional_domain_name": "snowpipe-stage.s3.ap-southeast-2.amazonaws.com",
    
          "cors_rule": [],
          "force_destroy": false,
          "grant": [],
          "hosted_zone_id": "Z1WCIGYICN2BYD",
          "id": "snowpipe-stage",
          "lifecycle_rule": [],
          "logging": [],
          "object_lock_configuration": [],
          "policy": null,
          "region": "ap-southeast-2",
          "replication_configuration": [],
          "request_payer": "BucketOwner",
    
          "server_side_encryption_configuration": [
            {
              "rule": [
                {
                  "apply_server_side_encryption_by_default": [
                    {
                      "kms_master_key_id": "arn:aws:kms:ap-southeast-2:692401932224:alias/snowflake_stage",
    
                      "sse_algorithm": "aws:kms"
                    }
                  ]
                }
              ]
            }
          ],
          "tags": {
            "DateModified": "2020-03-15T21:20:53",
            "Origin": "Terraform",
            "Project": "Cloud Project"
          },
          "versioning": [
            {
              "enabled": false,
              "mfa_delete": false
            }
          ],
          "website": [],
          "website_domain": null,
          "website_endpoint": null
        },
        "private": "bnVsbA=="
      }
    ]
    
    

    Additional context Attached is the terraform.tfstate file to read from. I had to rename it to .txt so as to be able to attach it to this issue. You can rename back to .tfstate on your local machine

    terraform.tfstate.txt

  • [BUG] Service resolution algorithm does not work properly when --usenonpreferredapis is invoked

    [BUG] Service resolution algorithm does not work properly when --usenonpreferredapis is invoked

    Describe the bug

    The SHOW RESOURCES command cannot properly resolve services when --usenonpreferredapis is invoked. This is likely because of ambiguity in the name field.

    This example snippet is illustrative...

    InfraQL* >>show extended resources from google.compute;
    Could not find Service: 'compute' from Provider: 'google'
    InfraQL* >>show services like '%compute%';
    |----------------|---------|--------------------|
    |       ID       |  NAME   |       TITLE        |
    |----------------|---------|--------------------|
    | compute__alpha | compute | Compute Engine API |
    |----------------|---------|--------------------|
    | compute__beta  | compute | Compute Engine API |
    |----------------|---------|--------------------|
    | compute__v1    | compute | Compute Engine API |
    |----------------|---------|--------------------||--------------------|--------------------------------|---------|-----------|
    InfraQL* >>
    

    ...note that there are 3 services with name = 'compute' and despite the use of '--nonpreferredapisit seems intuitive that the algorithm would resolve thepreferred` option (column not show but FYI third row is preferred).

    To Reproduce Steps to reproduce the behavior:

    1. Open the shell with ./infraql --verbose shell --usenonpreferredapis
    2. Run command show extended resources from google.compute;
    3. Observe output

    Expected behavior

    The service which is preferred should be returned from show extended resources from google.{SERVICE_NAME};, regardless of multiplicity of {SERVICE_NAME}.

    Screenshots

    Screen Shot 2020-12-05 at 1 18 42 pm

    Desktop (please complete the following information):

    • OS: [e.g. iOS]
    • Browser [e.g. chrome, safari]
    • Version [e.g. 22]

    Smartphone (please complete the following information):

    • Device: [e.g. iPhone6]
    • OS: [e.g. iOS8.1]
    • Browser [e.g. stock browser, safari]
    • Version [e.g. 22]

    Additional context Add any other context about the problem here.

  • [FEATURE] Add SET grammar to IQL

    [FEATURE] Add SET grammar to IQL

    Feature Description Add the SET command to the IQL grammar

    SET property value

    properties can be either:

    1. global flags for infraql (such as --keyfilepath); or
    2. provider properties including:
    • gcpproject (GCP project)
    • gcpregion (GCP region)
    • proxy/address (possibly make the proxy settings global flags)
    • proxy/port
    • proxy/username
    • proxy/password
  • [FEATURE] Enable SHOW COLUMNS or FIELDS support

    [FEATURE] Enable SHOW COLUMNS or FIELDS support

    Feature Description Add SHOW COLUMNS or SHOW FIELDS IQL meta operation, to filter columns from a resource

    The syntax would be

    SHOW [EXTENDED] {COLUMNS | FIELDS}
        {FROM | IN} _resource_
        [{FROM | IN} _service_]
        [LIKE 'pattern' | WHERE expr]
    

    SHOW COLUMNS IN resource without any filter is an alias for DESCRIBE resource

    SHOW EXTENDED COLUMNS IN resource without any filter is an alias for DESCRIBE EXTENDED resource

Use SQL to query host, DNS and exploit information using Shodan. Open source CLI. No DB required.

Shodan Plugin for Steampipe Query Shodan with SQL Use SQL to query host, DNS and exploit information using Shodan. For example: select * from shod

Nov 10, 2022
Go-Postgresql-Query-Builder - A query builder for Postgresql in Go

Postgresql Query Builder for Go This query builder aims to make complex queries

Nov 17, 2022
write APIs using direct SQL queries with no hassle, let's rethink about SQL

SQLer SQL-er is a tiny portable server enables you to write APIs using SQL query to be executed when anyone hits it, also it enables you to define val

Jan 7, 2023
A Go SQL query builder and struct mapper.

godb - a Go query builder and struct mapper godb is a simple Go query builder and struct mapper, not a full-featured ORM. godb does not manage relatio

Dec 6, 2022
Use SQL to instantly query file, domain, URL and IP scanning results from VirusTotal.
Use SQL to instantly query file, domain, URL and IP scanning results from VirusTotal.

VirusTotal Plugin for Steampipe Use SQL to query file, domain, URL and IP scanning results from VirusTotal. Get started → Documentation: Table definit

Nov 10, 2022
Use SQL to instantly query users, groups, applications and more from Okta. Open source CLI. No DB required.
Use SQL to instantly query users, groups, applications and more from Okta. Open source CLI. No DB required.

Okta Plugin for Steampipe Use SQL to query infrastructure including users, groups, applications and more from Okta. Get started → Documentation: Table

Nov 10, 2022
Use SQL to instantly query instances, networks, databases, and more from Scaleway. Open source CLI. No DB required.
Use SQL to instantly query instances, networks, databases, and more from Scaleway. Open source CLI. No DB required.

Scaleway Plugin for Steampipe Use SQL to query infrastructure servers, networks, databases and more from your Scaleway project. Get started → Document

Nov 16, 2022
Use SQL to query information including Users, Groups, Clients, Roles and more from Keycloak.

Keycloak Plugin for Steampipe [WIP] THIS IS NOT ACTIVE NOR WORKING YET - DO NOT USE Use SQL to query information including Users, Groups, Clients, Rol

Jan 6, 2023
Use SQL to query instances, domains and more from Prometheus.
Use SQL to query instances, domains and more from Prometheus.

Use SQL to instantly query Prometheus metrics, alerts, labels and more. Open source CLI. No DB required.

Nov 28, 2022
Use SQL to instantly query resources, data sources and more from Terraform code. Open source CLI. No DB required.
Use SQL to instantly query resources, data sources and more from Terraform code. Open source CLI. No DB required.

Terraform Plugin for Steampipe Use SQL to query data from Terraform configuration files. Get started → Documentation: Table definitions & examples Com

Dec 22, 2022
Use SQL to instantly query Algolia indexes and configuration. Open source CLI. No DB required

Use SQL to instantly query Algolia indexes and configuration. Open source CLI. No DB required

Oct 1, 2022
Use SQL to query databases, logs and more from PlanetScale

Use SQL to instantly query PlanetScale databases, branches and more. Open source CLI. No DB required.

Sep 30, 2022
Query redis with SQL
Query redis with SQL

reqlite reqlite makes it possible to query data in Redis with SQL. Queries are executed client-side with SQLite (not on the redis server). This projec

Dec 23, 2022
Use SQL to instantly query Datadog resources across accounts. Open source CLI. No DB required.

steampipe-plugin-datadog Datadog Plugin for Steampipe Use SQL to query dashboards, users, roles and more from Datadog. Get started → Documentation: Ta

Dec 17, 2022
Use SQL to instantly query Hypothesis resources. Open source CLI. No DB required.

Hypothesis Plugin for Steampipe Prerequisites Steampipe Golang Build $ git clone https://github.com/judell/steampipe-plugin-hypothesis.git $ cd steam

Dec 11, 2022
This is the code example how to use SQL to query data from any relational databases in Go programming language.

Go with SQL example This is the code example how to use SQL to query data from any relational databases in Go programming language. To start, please m

Mar 12, 2022
Parses a file and associate SQL queries to a map. Useful for separating SQL from code logic

goyesql This package is based on nleof/goyesql but is not compatible with it any more. This package introduces support for arbitrary tag types and cha

Oct 20, 2021
Go-sql-reader - Go utility to read the externalised sql with predefined tags

go-sql-reader go utility to read the externalised sql with predefined tags Usage

Jan 25, 2022
Dumpling is a fast, easy-to-use tool written by Go for dumping data from the database(MySQL, TiDB...) to local/cloud(S3, GCP...) in multifarious formats(SQL, CSV...).

?? Dumpling Dumpling is a tool and a Go library for creating SQL dump from a MySQL-compatible database. It is intended to replace mysqldump and mydump

Nov 9, 2022