Commit Graph

20 Commits

Author SHA1 Message Date
Kumar, Nishant (nk613n) a2606e75b1 Remove unused code for policy validation as feature not implemented
Policy validation in Deckhand was not implemented completely. Refer link
below:
https://airshipit.readthedocs.io/projects/deckhand/en/latest/users/validation.html#policy-validations

This PS removes some of the code related to the feature which was being
used in a code path when a set of documents are uploaded to Deckhand.
In standard Airship deployments the number of documents could be quite
high and this leads to significant delay (more than 300seconds in some
cases). As there are no plans to implement the policy validation feature,
it makes sense to remove it from code path which could cause delay and
sometimes timeouts while uploading documents.

This has been tested on a Baremetal lab: GF and BF.

Change-Id: I2ff3f40a7fe37bed5a589fab00d829db726604fe
2020-05-14 00:34:42 +00:00
Felipe Monteiro b03a4522cb fix: Use schema instead of metadata.schema for replacement check
Recently added replacement check incorrectly uses metadata.schema
and metadata.name to key on the document -- but it should be schema
and metadata.name, the combination of which uniquely defines a
document.

Change-Id: I6cd1679ad41be38cb78d65ce2763e60f7da390d2
2018-10-31 15:02:28 -04:00
Felipe Monteiro 11eeb69f44 integration tests: Add Barbican validation/assertions
This patchset adds Barbican validation/assertions to integration
tests by querying the Barbican API server where appropriate
and validating that the expected data is returned in order
to sanity-check the integration scenarios further.

Change-Id: If5d30712b289f09ac9712ee205673be4150cda16
2018-07-22 16:32:57 +00:00
Scott Hussey e40f3e443f Simplify schema validation
- Treat internal Deckhand schemas equivalent to other
  service schemas
- Remove validating sections other than `data` outside of
  base schema
- Create schemas for metadata sections metadata/Control/v1 and
  metadata/Document/v1
- Use a single validator and let that validator check for document
  structure (validate against the base schema and metadata)
  and for post-validation also validate against service schemas

Change-Id: I5f9b9a3cfa1692a69b5982a6424edd65bdfed0ef
2018-07-03 02:07:33 +00:00
Felipe Monteiro d02e1bcf53 [feature] Endpoint for listing revision validations with details
This patch set adds a new endpoint to the Validations API which allows
for listing all validations for a given revision with details.
The response body for GET /api/v1.0/{revision_id}/validations/detail
looks like:

  ---
  count: 1
  next: null
  prev: null
  results:
    - name: promenade-site-validation
      url: https://deckhand/api/v1.0/revisions/4/validations/promenade-site-validation/entries/0
      status: failure
      createdAt: 2017-07-16T02:03Z
      expiresAfter: null
      expiresAt: null
      errors:
        - documents:
            - schema: promenade/Node/v1
              name: node-document-name
            - schema: promenade/Masters/v1
              name: kubernetes-masters
          message: Node has master role, but not included in cluster masters list.

Note that the Validations API in general is currently missing fields
like url (as well as next and prev references) which will be included
in a follow up.

This will enable Shipyard to avoid performing a quadratic number
of API look ups when querying Deckhand's Validations API: [0].

The policy enforced for this endpoint is deckhand:list_validations.

APIImpact
DocImpact

[0] 06b5e82ea8/shipyard_airflow/control/configdocs/deckhand_client.py (L265)

Change-Id: I827e5f47bffb23fa16ee5c8a705058034633baed
2018-04-29 01:37:38 +00:00
Felipe Monteiro 99e3064eda [test] Improve validation policy test coverage for success scenario
This is to follow up on https://review.gerrithub.io/#/c/398708/
with more complete coverage for validation policy integration
with Validations API. The updated test covers both success and
failure paths.

Change-Id: I118c3783f98a3b38547745acc642d00d188f0b2e
2018-03-30 10:21:09 -04:00
Felipe Monteiro 1264e5af6c Document replacement: Update Document unique constraint
This updates the unique constraint for Document model from
schema/metadata.name to schema/metadata.name/layer which is
a pre-requisite for document replacement implementation.

The remainder fo the changes are taken of in child PS
(particulary those related to the layering module):
https://review.gerrithub.io/#/c/403888/

Change-Id: Icc4f4960b3a3951f649c7886dbe0bce77341a9f7
2018-03-28 17:08:03 -04:00
Felipe Monteiro cce6ddaf6e Fix uniqueness not being enforced at DB level for documents
UniqueConstraint is currently implemented incorrectly in terms
of syntax in Deckhand's Document DB model. This PS fixes that.
Now UniqueConstraint should be enforcing document uniqueness
at DB level such that an error is thrown for duplicate documents
(with same metadata.name and schema).

Closes #17

Change-Id: I7d66457f471ec48b5766733046977117b509d592
2018-03-22 05:57:19 -04:00
Felipe Monteiro 5c411dd05b Fix: Document should not layer with parent if no layering actions
Currently, if a document has a parent but no layering actions,
the document immediately inherents its parents' data, which is a
bug. Instead, the child document should only layer with its
parent's data and then update its own data if it has at least
one layering action.

In addition, the base_schema.yaml under `deckhand.schemas`
has been updated to require that actions be required and
contain at least 1 layering action when parentSelector
is provided and that parentSelector be required when
actions is provided and that at least one key-value
pair be provided. (Empty actions array or empty
parentSelector object is meaningless and should be
disallowed/discouraged.)

This means that actions and parentSelector must always
both be provided (though providing neither is also
legal because layering is optional).

Unit tests have been added to verify the schema updates.

Change-Id: I77d54e2b216efc54b466f94d82ee8d36ca169c26
2018-03-15 12:27:31 -04:00
Felipe Monteiro d82d0cfaf7 ValidationPolicy integration with Validations API
This PS integrates ValidationPolicy logic with the
Deckhand Validations API.

Support for multiple ValidationPolicy documents is
included.

If a ValidationPolicy is found, then the validations
contained therein are used to determine whether
a revision is successful or not. For example,
if a VP contains 'promenade-schema-validation' then
DH will return success if the externally registered
validation result for that validation is success.
However, if the result was never registered in DH
then the returned result is 'failure'.

In addition, if "extra" validations are registered
(that is validations not present in any VP) then
they are effectively ignored. An error message is
added with enough details to indicate why the validation
is ignored.

This PS adds unit tests to verify the correct behavior
for the above scenarios.

Functional tests and documentation changes will be added
in a follow up once design is ironed out.

Change-Id: I44c657974589ea3563e0a23ad667894329048b46
2018-03-12 12:41:06 -04:00
Felipe Monteiro e0fc59e89b Deckhand schemas as YAML files
Use YAML formatting for built-in Deckhand schemas
used for validations to align with other UCP services.

The second most important intention behind this PS
is to allow pre_validate flag to cascade correctly
between the layering and document_validation modules.

If pre_validate is true, then:
  * the base_schema validates ALL documents
  * ALL built-in schemas validate the appropriate
    document given a schema match
  * NO externally registered DataSchema documents
    are used for validation

Else (if pre_validate is false):
  * the base_schema validates ALL documents
  * ALL built-in schemas validate the appropriate
    document given a schema match
  * ALL externally registered DataSchema documents
    are used for validation given a schema match

A more minor change is setting pre_validate flags in
all modules to True for consistency. The idea is to
facilitate the way other projects that import Deckhand
in directly interface with Deckhand.

Change-Id: I859f61989ec15bede1c104b86625d116064f056d
2018-02-27 11:16:30 -05:00
Felipe Monteiro 02528bc3af Reduce number of pre-validation false positives
Currently Pegleg uses a lot of raw documents that are missing
properties at first because those properties are only included
in the documents only after they undergo substitution (are rendered).
This means that when these raw documents are PRE-validated against
registered DataSchemas a lot of noise is created.

However, after the documents are rendered (undergo substitution)
then they should be POST-validated against the registered DataSchemas.

This PS makes the changes necessary to make pre-validation ignore
validation against registered DataSchemas but makes post-validation
raise all validation errors while validating against all built-in
and registered schemas.

Necessary changes were made to tests to make them pass with the
new changes. A follow up will be needed to do better testing
for pre-validation vs. post-validation but the functional test
scenario in schema-validation-success.yaml should test both
scenarios.

Change-Id: I5c139fa528639d43fc45eda067a9ea807fe26c61
2018-02-12 11:06:22 -05:00
Felipe Monteiro 021090516b Improve validation error messages returned by Deckhand
Currently the format of the validation error messages returned
by the Deckhand Validation API is lacking. The new response is a
dictionary with the following keys:

    * validation_schema: The schema body that was used to validate the
        document.
    * schema_path: The JSON path in the schema where the failure originated.
    * name: The document name.
    * schema: The document schema.
    * path: The JSON path in the document where the failure originated.
    * error_section: The "section" in the document above which the error
        originated (i.e. the dict in which ``path`` is found).
    * message: The error message returned by the ``jsonschema`` validator.

This PS updates the document validation module and associated unit tests
to return and verify the above format.

Change-Id: I9ef1c36db85233cbfb866dea786228ef1416468c
2018-01-25 21:51:31 -05:00
Felipe Monteiro 453927facf Improve document validation module.
This PS rewrites the document_validation module in
Deckhand to achieve the following goals:

  * better validation resiliency
  * add support for different document schema versions
  * better support for DataSchema validation
  * separation of concerns by splitting up validations
    into separate classes
  * support for validating documents that rely on
    a DataSchema passed in via the same payload
  * support for generating multiple validation errors
    rather than returning after the first one found
  * increase testing validations for unit/functional
    tests

Better validation resiliency is achieved through more
robust exception handling. For example, it is possible
for a ``DataSchema`` to be 100% valid from the POV of
built-in schema validation, but if the "data" section
itself is utterly invalid, then an exception will be
raised -- such an exception is treated as a critical
failure.

Better generation of error messages is achieved by
creation more validation error message results.

DataSchema validation was previously wonky. A DataSchema
had to first be created in 1 revision before it could be
referenced by a batch of documents in sequential revisions.
Now, a DataSchema can be created in the same (or previous)
revision as documents that rely on it and used to validate
said documents.

Finally, the module was heavily rewritten so that more
nuanced validations can be built by inheriting from
``BaseValidator`` so as to allow for easier code
readability and maintainability.

Change-Id: Ie75742b984b7ad392cb41decc203d42842050c80
2018-01-15 16:51:52 -05:00
Bryan Strassner 805758da2e Align code with docs for validation entries
Documentation and some of the code indicated that the pattern
...validations/{validation_name}/entries/{id} would be used
Code had some artifacts using: ...validations/{validation_name}/{id}
This change addresses this and aligns on the documented version.

Change-Id: I71f4f2273464e60968eb026ee4f5db96ff3302c7
2017-11-07 14:20:46 -06:00
Felipe Monteiro 52a9632e40 Prevent same DataSchema from being used more than once for validation.
This PS prevents the same DataSchema from being used more than once
for validation. Otherwise the list of errors generated will be
duplicated.

Change-Id: I4eb1d33cdbe084ddea522b2c9ea91d507de4ca23
2017-11-01 09:54:53 -04:00
Felipe Monteiro b22fa5d2f3 Deckhand Negative RBAC test scenarios
The framework for being able to do RBAC unit testing
in Deckhand was added here:

    #I86f269a5b616b518e5f742a4005891412226fe2a
    https://review.gerrithub.io/#/c/381205/

This PS expands on that foundation by implementing
negative RBAC tests for the remainder of the Deckhand
APIs. Negative testing means attempting to call APIs
with insufficient permissions and expecting 403s or
empty response bodies, depending on whether the
policy enforcement is critical or conditionally
applied.

Also fixes a minor bug related to returning a deleted
document for the endpoint PUT /api/v1.0/bucket/{bucket_name}/documents

Change-Id: I7ae50f300c1c877c3c162a032611a380f8948065
2017-10-31 17:37:39 +00:00
Felipe Monteiro c729cd930d Rename Deckhand bucket endpoint to buckets for consistency
According to guides like [0] RESTful resource name should
use pluralization for nouns, for the sake of consistency.

As such, this PS renames PUT bucket/{bucket_name}/documents
to PUT buckets/{bucket_name}/documents

Required renames have also been made to the following UCP
projects:

  - Shipyard -> https://review.gerrithub.io/#/c/384121/

[0] https://restfulapi.net/resource-naming/

Change-Id: Icb01e29db0b8b12e66895135baa9be525ba7d72b
2017-10-27 19:21:03 +01:00
Felipe Monteiro 183c718f46 Make middleware enforce and validate content-type
This PS manually removes logic for adding application/x-yaml
content type inside controllers and moves it into a better
layer of abstraction: middleware.

This PS also fixes a bug with using recently removed function
to_yaml_body from the VersionsResource and adds unit tests
for testing YAMLTranslator middleware.

Change-Id: I4388eb212efee7b300f242eebbc20e22b766fd7d
2017-10-23 17:02:01 +01:00
Felipe Monteiro 8aec0390f8 DECKHAND-80: Validations API Implementation
The Validations API has been introduced to Deckhand, allowing users
to register new validation results in Deckhand, as well as query
the API for validation results for a revision. The validation results
include a list of errors that occurred during document validation.

All functional tests related to the API are now passing.

The following endpoints have been implemented:

   * /api/v1.0/revisions/{revision_id}/validations
   * /api/v1.0/revisions/{revision_id}/validations/{validation_name}
   * /api/v1.0/revisions/{revision_id}/validations/{validation_name}/entries
   * /api/v1.0/revisions/{revision_id}/validations/{validation_name}/entries/{entry_id}

Some back-end refactoring was needed to implement this API. In
particular:

  - Added a new Validation sqlalchemy DB model
  - Introduced DataSchema handling to the engine.document_validation
    module so that registered schema validations can be used
  - Changed the way the result of the 'deckhand-schema-validation' internal
    validation is generated: it is now the amalgamation of all the
    internal and registered schema validations executed
  - Introduced rawquery generation so that raw SQL queries can be used to
    get results from DB

Fixed following bug:

  - UniqueConstraint is now used to correctly generate unique constraints
    for sqlalchemy models that are supposed to be combinations of columns

Change-Id: I53c79a6544f44ef8beab2600ddc8a3ea91ada903
2017-10-21 23:09:16 -04:00