google.cloud.forseti.scanner.audit.bigquery_rules_engine module

Rules engine for Big Query data sets.

class BigqueryRuleBook(rule_defs=None)[source]

Bases: google.cloud.forseti.scanner.audit.base_rules_engine.BaseRuleBook

The RuleBook for Big Query dataset resources.

_abc_cache = <_weakrefset.WeakSet object>
_abc_negative_cache = <_weakrefset.WeakSet object>
_abc_negative_cache_version = 186
_abc_registry = <_weakrefset.WeakSet object>
add_rule(rule_def, rule_index)[source]

Add a rule to the rule book.

Parameters:
  • rule_def (dict) – A dictionary containing rule definition properties.
  • rule_index (int) – The index of the rule from the rule definitions. Assigned automatically when the rule book is built.
add_rules(rule_defs)[source]

Add rules to the rule book.

Parameters:rule_defs (dict) – rule definitions dictionary.
get_resource_rules()[source]

Get all the resource rules for (resource, RuleAppliesTo.*).

Returns:A list of ResourceRules.
Return type:list
class BigqueryRulesEngine(rules_file_path, snapshot_timestamp=None)[source]

Bases: google.cloud.forseti.scanner.audit.base_rules_engine.BaseRulesEngine

Rules engine for Big Query data sets

add_rules(rules)[source]

Add rules to the rule book.

Parameters:rules (dict) – rule definitions dictionary
build_rule_book(global_configs=None)[source]

Build BigqueryRuleBook from the rules definition file.

Parameters:global_configs (dict) – Global configurations.
find_policy_violations(bq_datasets, force_rebuild=False)[source]

Determine whether Big Query datasets violate rules.

Parameters:
  • bq_datasets (list) – Object containing ACL data.
  • force_rebuild (bool) – If True, rebuilds the rule book. This will reload the rules definition file and add the rules to the book.
Returns:

A generator of rule violations.

Return type:

generator

class Rule(rule_name, rule_index, rules)[source]

Bases: object

Rule properties from the rule definition file. Also finds violations.

class RuleViolation(domain, resource_data, resource_id, special_group, group_email, rule_name, role, user_email, full_name, rule_index, violation_type, dataset_id, resource_type, view)

Bases: tuple

__getnewargs__()

Return self as a plain tuple. Used by copy and pickle.

__getstate__()

Exclude the OrderedDict from pickling

__repr__()

Return a nicely formatted representation string

_asdict()

Return a new OrderedDict which maps field names to their values

_fields = ('domain', 'resource_data', 'resource_id', 'special_group', 'group_email', 'rule_name', 'role', 'user_email', 'full_name', 'rule_index', 'violation_type', 'dataset_id', 'resource_type', 'view')
classmethod _make(iterable, new=<built-in method __new__ of type object>, len=<built-in function len>)

Make a new RuleViolation object from a sequence or iterable

_replace(**kwds)

Return a new RuleViolation object replacing specified fields with new values

dataset_id
domain
full_name
group_email
resource_data
resource_id
resource_type
role
rule_index
rule_name
special_group
user_email
view
violation_type
find_policy_violations(bigquery_acl)[source]

Find BigQuery acl violations in the rule book.

Parameters:bigquery_acl (BigqueryAccessControls) – BigQuery ACL resource.
Yields:namedtuple – Returns RuleViolation named tuple.
frozen_rule_attributes = frozenset(['domain', 'resource_data', 'resource_id', 'special_group', 'group_email', 'rule_name', 'role', 'user_email', 'full_name', 'rule_index', 'violation_type', 'dataset_id', 'resource_type', 'view'])
rule_violation_attributes = ['resource_type', 'resource_id', 'full_name', 'rule_name', 'rule_index', 'violation_type', 'dataset_id', 'role', 'special_group', 'user_email', 'domain', 'group_email', 'view', 'resource_data']