Browse Source

Cloud Function gateway

ref:f6ff1d18198749d377882291ee9ef9c4330b708d
hrustyashko 2 years ago
parent
commit
c44713288e

+ 9 - 0
CMakeLists.darwin.txt

@@ -1199,6 +1199,15 @@ add_subdirectory(ydb/library/yql/parser/pg_catalog/ut)
 add_subdirectory(ydb/library/yql/providers/common/schema)
 add_subdirectory(ydb/library/yql/providers/common/schema/skiff)
 add_subdirectory(ydb/library/yql/providers/cloud_function/actors)
+add_subdirectory(ydb/library/yql/providers/cloud_function/gateway)
+add_subdirectory(cloud/bitbucket/private-api/yandex/cloud/priv/serverless/functions/v1)
+add_subdirectory(contrib/libs/googleapis-common-protos)
+add_subdirectory(cloud/bitbucket/common-api/yandex/cloud/api)
+add_subdirectory(cloud/bitbucket/common-api/yandex/cloud/api/tools)
+add_subdirectory(cloud/bitbucket/private-api/yandex/cloud/priv)
+add_subdirectory(cloud/bitbucket/private-api/yandex/cloud/priv/access)
+add_subdirectory(cloud/bitbucket/private-api/yandex/cloud/priv/operation)
+add_subdirectory(cloud/bitbucket/private-api/yandex/cloud/priv/quota)
 add_subdirectory(ydb/library/yql/public/decimal/ut)
 add_subdirectory(ydb/library/yql/public/issue/ut)
 add_subdirectory(ydb/library/yql/public/udf/ut)

+ 9 - 0
CMakeLists.linux.txt

@@ -1294,6 +1294,15 @@ add_subdirectory(ydb/library/yql/parser/pg_catalog/ut)
 add_subdirectory(ydb/library/yql/providers/common/schema)
 add_subdirectory(ydb/library/yql/providers/common/schema/skiff)
 add_subdirectory(ydb/library/yql/providers/cloud_function/actors)
+add_subdirectory(ydb/library/yql/providers/cloud_function/gateway)
+add_subdirectory(cloud/bitbucket/private-api/yandex/cloud/priv/serverless/functions/v1)
+add_subdirectory(contrib/libs/googleapis-common-protos)
+add_subdirectory(cloud/bitbucket/common-api/yandex/cloud/api)
+add_subdirectory(cloud/bitbucket/common-api/yandex/cloud/api/tools)
+add_subdirectory(cloud/bitbucket/private-api/yandex/cloud/priv)
+add_subdirectory(cloud/bitbucket/private-api/yandex/cloud/priv/access)
+add_subdirectory(cloud/bitbucket/private-api/yandex/cloud/priv/operation)
+add_subdirectory(cloud/bitbucket/private-api/yandex/cloud/priv/quota)
 add_subdirectory(ydb/library/yql/public/decimal/ut)
 add_subdirectory(ydb/library/yql/public/issue/ut)
 add_subdirectory(ydb/library/yql/public/udf/ut)

+ 7 - 0
cloud/README.md

@@ -0,0 +1,7 @@
+# Yandex Cloud (https://wiki.yandex-team.ru/cloud)
+
+This repository used for YC projects
+Another repositories - https://bb.yandex-team.ru/projects/CLOUD/
+
+Please contact devel@yandex-team.ru for any support
+

+ 0 - 0
cloud/__init__.py


+ 53 - 0
cloud/bitbucket/common-api/yandex/cloud/api/CMakeLists.txt

@@ -0,0 +1,53 @@
+
+# This file was gererated by the build system used internally in the Yandex monorepo.
+# Only simple modifications are allowed (adding source-files to targets, adding simple properties
+# like target_include_directories). These modifications will be ported to original
+# ya.make files by maintainers. Any complex modifications which can't be ported back to the
+# original buildsystem will not be accepted.
+
+
+
+add_library(yandex-cloud-api)
+set_property(TARGET yandex-cloud-api PROPERTY
+  PROTOC_EXTRA_OUTS .grpc.pb.cc .grpc.pb.h
+)
+target_include_directories(yandex-cloud-api PUBLIC
+  ${CMAKE_BINARY_DIR}/cloud/bitbucket/common-api
+)
+target_include_directories(yandex-cloud-api PRIVATE
+  ${CMAKE_BINARY_DIR}/cloud/bitbucket/common-api
+)
+target_link_libraries(yandex-cloud-api PUBLIC
+  contrib-libs-cxxsupp
+  yutil
+  contrib-libs-grpc
+  contrib-libs-googleapis-common-protos
+  cloud-api-tools
+  contrib-libs-protobuf
+)
+target_proto_messages(yandex-cloud-api PRIVATE
+  ${CMAKE_SOURCE_DIR}/cloud/bitbucket/common-api/yandex/cloud/api/operation.proto
+)
+target_sources(yandex-cloud-api PRIVATE
+  ${CMAKE_BINARY_DIR}/cloud/bitbucket/common-api/yandex/cloud/api/operation.pb.cc
+)
+target_proto_addincls(yandex-cloud-api
+  ./cloud/bitbucket/common-api
+  ${CMAKE_SOURCE_DIR}/cloud/bitbucket/common-api
+  ${CMAKE_BINARY_DIR}
+  ${CMAKE_SOURCE_DIR}
+  ${CMAKE_SOURCE_DIR}/cloud/bitbucket/common-api
+  ${CMAKE_SOURCE_DIR}/contrib/libs/googleapis-common-protos
+  ${CMAKE_SOURCE_DIR}/contrib/libs/protobuf/src
+  ${CMAKE_SOURCE_DIR}/cloud/bitbucket/common-api
+  ${CMAKE_BINARY_DIR}
+  ${CMAKE_SOURCE_DIR}/contrib/libs/protobuf/src
+)
+target_proto_outs(yandex-cloud-api
+  --cpp_out=${CMAKE_BINARY_DIR}/cloud/bitbucket/common-api
+  --cpp_styleguide_out=${CMAKE_BINARY_DIR}/cloud/bitbucket/common-api
+)
+target_proto_plugin(yandex-cloud-api
+  grpc_cpp
+  grpc_cpp
+)

+ 24 - 0
cloud/bitbucket/common-api/yandex/cloud/api/operation.proto

@@ -0,0 +1,24 @@
+syntax = "proto3";
+
+package yandex.cloud.api;
+
+import "google/protobuf/descriptor.proto";
+import "yandex/cloud/api/tools/options.proto";
+
+option go_package = "a.yandex-team.ru/cloud/bitbucket/common-api/yandex/cloud/api;api";
+option (cloud.api.tools.file).lint_skip.java_package = true;
+
+extend google.protobuf.MethodOptions { Operation operation = 87334; }
+
+// Operation is annotation for rpc that returns longrunning operation, describes
+// message types that will be returned in metadata [google.protobuf.Any], and
+// in response [google.protobuf.Any] (for successful operation).
+message Operation {
+  // Optional. If present, rpc returns operation which metadata field will
+  // contains message of specified type.
+  string metadata = 1; // Optional.
+
+  // Required. rpc returns operation, in case of success response will contains message of
+  // specified field.
+  string response = 2; // Required.
+}

+ 51 - 0
cloud/bitbucket/common-api/yandex/cloud/api/tools/CMakeLists.txt

@@ -0,0 +1,51 @@
+
+# This file was gererated by the build system used internally in the Yandex monorepo.
+# Only simple modifications are allowed (adding source-files to targets, adding simple properties
+# like target_include_directories). These modifications will be ported to original
+# ya.make files by maintainers. Any complex modifications which can't be ported back to the
+# original buildsystem will not be accepted.
+
+
+
+add_library(cloud-api-tools)
+set_property(TARGET cloud-api-tools PROPERTY
+  PROTOC_EXTRA_OUTS .grpc.pb.cc .grpc.pb.h
+)
+target_include_directories(cloud-api-tools PUBLIC
+  ${CMAKE_BINARY_DIR}/cloud/bitbucket/common-api
+)
+target_include_directories(cloud-api-tools PRIVATE
+  ${CMAKE_BINARY_DIR}/cloud/bitbucket/common-api
+)
+target_link_libraries(cloud-api-tools PUBLIC
+  contrib-libs-cxxsupp
+  yutil
+  contrib-libs-grpc
+  contrib-libs-googleapis-common-protos
+  contrib-libs-protobuf
+)
+target_proto_messages(cloud-api-tools PRIVATE
+  ${CMAKE_SOURCE_DIR}/cloud/bitbucket/common-api/yandex/cloud/api/tools/options.proto
+)
+target_sources(cloud-api-tools PRIVATE
+  ${CMAKE_BINARY_DIR}/cloud/bitbucket/common-api/yandex/cloud/api/tools/options.pb.cc
+)
+target_proto_addincls(cloud-api-tools
+  ./cloud/bitbucket/common-api
+  ${CMAKE_SOURCE_DIR}/cloud/bitbucket/common-api
+  ${CMAKE_BINARY_DIR}
+  ${CMAKE_SOURCE_DIR}
+  ${CMAKE_SOURCE_DIR}/cloud/bitbucket/common-api
+  ${CMAKE_SOURCE_DIR}/contrib/libs/googleapis-common-protos
+  ${CMAKE_SOURCE_DIR}/contrib/libs/protobuf/src
+  ${CMAKE_BINARY_DIR}
+  ${CMAKE_SOURCE_DIR}/contrib/libs/protobuf/src
+)
+target_proto_outs(cloud-api-tools
+  --cpp_out=${CMAKE_BINARY_DIR}/cloud/bitbucket/common-api
+  --cpp_styleguide_out=${CMAKE_BINARY_DIR}/cloud/bitbucket/common-api
+)
+target_proto_plugin(cloud-api-tools
+  grpc_cpp
+  grpc_cpp
+)

+ 87 - 0
cloud/bitbucket/common-api/yandex/cloud/api/tools/options.proto

@@ -0,0 +1,87 @@
+syntax = "proto3";
+
+package yandex.cloud.api.tools;
+
+import "google/protobuf/descriptor.proto";
+
+option go_package = "a.yandex-team.ru/cloud/bitbucket/common-api/yandex/cloud/api/tools;tools";
+option (cloud.api.tools.file).lint_skip.java_package = true;
+
+// NOTE(skipor): option extention names should have package scope unique names
+// and global unique ids per Options type from range 50000-99999 reserved for internal use.
+
+extend google.protobuf.FileOptions {FileOptions file = 67321;}
+extend google.protobuf.MessageOptions {MessageOptions message = 67321;}
+extend google.protobuf.FieldOptions {FieldOptions field = 67321;}
+extend google.protobuf.EnumOptions {EnumOptions enumeration = 67321;} // enum is reserved word :(
+extend google.protobuf.EnumValueOptions {EnumValueOptions value = 67321;}
+extend google.protobuf.ServiceOptions {ServiceOptions service = 67321;}
+extend google.protobuf.MethodOptions {MethodOptions method = 67321;}
+
+message FileOptions {
+  FileLintSkip lint_skip = 1;
+}
+
+message FileLintSkip {
+  bool all = 1;
+  bool go_package = 2;
+  bool file_path = 3;
+  bool java_package = 4;
+}
+
+message MessageOptions {
+  CommonLintSkip lint_skip = 1;
+  string openapi_name = 2;
+}
+
+message FieldOptions {
+  // Used to declare which schema may have protobuf.Struct field.
+  // TODO(skipor): if v1 and later apis use it move it to yandex.cloud.api package, and parse
+  // at lint stage, but not at options parse.
+  repeated string one_of = 1;
+  FieldLintSkip lint_skip = 2;
+}
+
+message FieldLintSkip {
+  bool all = 1;
+  bool int_type = 2;
+  bool float_type = 3;
+  bool json_name = 4;
+}
+
+message EnumOptions {
+  EnumLintSkip lint_skip = 2;
+  string openapi_name = 3;
+}
+
+message EnumLintSkip {
+  bool all = 1;
+  bool value_names_case = 2;
+  bool unspecified_value = 3;
+}
+
+message EnumValueOptions {
+  CommonLintSkip lint_skip = 1;
+}
+
+message ServiceOptions {
+  CommonLintSkip lint_skip = 1;
+  bool skip_generate = 2;
+}
+
+message MethodOptions {
+  MethodLintSkip lint_skip = 1;
+  bool skip_generate = 2;
+}
+
+message MethodLintSkip {
+  bool all = 1;
+  bool contains_resource_name = 2;
+  bool http_query_parameters = 3;
+  bool http_path = 4;
+  bool http_verb = 5;
+}
+
+message CommonLintSkip {
+  bool all = 1;
+}

+ 52 - 0
cloud/bitbucket/private-api/README.md

@@ -0,0 +1,52 @@
+## Private API development guide
+
+All cloud control plane API definition based on [gRPC](https://grpc.io).
+
+### Repository setup
+#### Prerequisites
+
+- make
+- on Mac OS X, protoc (should be >= 3.5) or Homebrew (protoc will be installed using brew)
+- on Linux, protoc (should be >= 3.5) or sudo access to install it from github
+
+#### Steps
+
+Example:
+
+```
+git clone https://bb.yandex-team.ru/scm/cloud/private-api.git
+cd private-api
+
+// ...Hack-hack-hack...
+
+make lint
+```
+
+### Checking proto compilation locally
+
+Just run `make lint` inside src root.
+To build proto tools from source set 'BUILD_TOOLS' variable to 1.
+Also you may check compilation of swagger docs out of cloud API: run `make generate` for that.
+
+For Pull Request build both successful `lint` and `generate` required.
+
+
+#### Validation
+
+Normally, all the fields of all messages received from users must be validated:
+- Request messages;
+- Value objects used in request messages;
+- Value objects used in value objects and so on.
+
+Output messages does not require validation.
+
+Syntax and examples can be found in ``yandex/cloud/priv/example/v1alpha/validation_example.proto``
+
+For Java developers there is ``java`` module, ``mvn clean package`` in this directory does following:
+ - builds and packages all proto-files in the repository
+ - tests all validators for syntax and applicability
+ - includes yandex.cloud.proto.ProtoValidator which helps validating messages in grpc interceptor.
+
+The `java/do_local_install.sh` script is useful for local development of a feature branch.
+The script will run `mvn versions:set && mvn clean install` and install built artifacts 
+in the local maven repo with snapshot version. Please run `versions:revert` manually if script failed at compilation.

+ 108 - 0
cloud/bitbucket/private-api/README.roles.md

@@ -0,0 +1,108 @@
+# identity-role-access-matrix
+
+Этот документ описывает новый формат хранения данных о well-known сущностях IAM'а.
+
+Пермишены и сервисные роли хранятся в отдельном каталоге для сервиса, который ими управляет. 
+Например, пермишен `compute.instances.start` может быть задан в файле `compute/permissions.yaml`, а роль `resource-manager.clouds.member` — в файле `resource-manager/roles.yaml`.
+Внутри своего каталога команда сервиса может организовать данные как угодно, одним файлом или несколькими, положить их в одном каталоге или раскидать по поддиректориям. 
+Обязательное требование — файлы внутри подкаталогов должны называться `permissions.yaml`, `roles.yaml`, `stages.yaml`, `resources.yaml` для описания набора прав, ролей, стейджей и типов ресурсов соответсвенно. 
+В каждом файле можно сослаться на сущность из любого другого файла — точно так же, как если бы сущности были описаны рядом, явно ссылаться на файл не нужно.
+
+Если эта документация противоречит тому, что на самом деле творится в файлах — значит, в файлах неправильно :)
+
+## Тулинг
+
+Для проверки того, что yaml'ы написаны верно, можно воспользоваться `yc-iam-compile-role-fixtures` из Python-пакета [yc_iam_tools](https://bb.yandex-team.ru/projects/CLOUD/repos/identity/browse/iam_tools/yc_iam_tools/). А можно и не пользоваться, такая же проверка запускается в TeamCity на каждый PR.
+
+## Роли
+
+```yaml
+roles:
+   # В этом dict'е перечисляются роли: ключ — название роли, значение — dict со свойствами
+   
+   example.editor:  # название роли
+   
+     # Описание роли на английском для документации.
+     summary: |>
+       Edit different things that are managed by ExampleService.
+       Users with this role are also allowed to whisper to horses.
+     
+     # Видимость роли: может быть public или internal. Роли public видят пользователи, а internal роли — нет.
+     # Public роль не должна включать в себя internal-пермишены, сейчас это warning при компиляции,
+     # в будущем повысим до error.
+     visibility: public
+     
+     # Минимальный тип ресурса, на который можно назначить роль.
+     resourceType: resource-manager.folder
+     # Эту роль можно назначить на фолдер или на клауд, но нельзя на SA или на биллинг-аккаунт.
+     # Такая роль может содержать пермишены, у которых resourceType фолдер или какой-нибудь вложенный в него ресурс,
+     # но не может содержать никакие другие пермишены.
+     
+     # Другие роли, входящие в состав этой.
+     # Параметр можно не указывать, если не нужно инклюдить никакие другие роли.
+     includedRoles:
+       - example.viewer
+       - horse.whisperer
+     # Роль `example.editor` содержит все пермишены из `example.viewer` и `horse.whisperer`.
+     # `includedRoles` работает транзитивно: если в определении `example.viewer` тоже инклюдятся какие-то роли,
+     # то их пермишены входят и в `example.editor`.
+       
+     # Пермишены, входящие в роль.
+     # Параметр можно не указывать, если роль не включает никаких пермишенов напрямую.
+     permissions:
+       - example.things.edit
+       - example.things.manage
+       # Есть сокращённая форма записи:
+       - example.thingCollections.{create,update,delete}
+       # Фигурные скобки можно использовать в любом месте записи:
+       # `sample.{horses,mice,chickens}.{feed,pet}` тоже можно сказать,
+       # эта запись разресолвится в 6 пермишенов.
+       # (Но лучше таким не злоупотреблять.)
+     
+     # В итоге получается, что в роль `example.editor` входят пермишены:
+     # `example.things.edit`, `example.things.manage`,
+     # `example.thingCollections.create`, `example.thingCollections.update`, `example.thingCollections.delete`,
+     # а также все пермишены, которые входят в роли `example.viewer` и `horse.whisperer`.
+     
+   # Ещё одна роль.
+   example.viewer:
+     # Эта роль используется в роли `example.editor` выше.
+     # Но это не значит, что `example.viewer` в файле должна идти после `example.editor` —
+     # можно расположить их хоть как или вообще положить в разные файлы.
+     ...
+```
+
+Роли задаются аддитивно: можно создать роль "`viewer` плюс `compute.editor` плюс `iam.serviceAccounts.create`", но нельзя задать "`viewer` минус `billing.viewer`" или "все пермишены `serverless.*.*`, кроме `serverless.*.delete`". Это сделано специально, чтобы при добавлении новой роли/пермишена вся система вела себя более предсказуемо.
+
+Некоторые роли помечены как "псевдороли", у них есть поле `pseudorole: true`. Это временные сущности, они нужны только для того, чтобы из них составить общеоблачные роли типа `viewer`. Ни внешние, ни внутренние пользователи не могут видеть псевдороли в API и назначать на ресурсы. Сервисам рекомендуется заменить их на правильные сервисные роли.
+
+## Пермишены
+
+```yaml
+permissions:
+
+  iam.accessBinding.delete:  # имя пермишена
+  
+    # Описание роли на английском для документации.
+    description: Delete access binding.
+    
+    # Стейдж. Чаще всего это GA.
+    # Список стейджей лежит в `stages.yaml`.
+    stage: GA
+    
+    # Видимость пермишена: может быть public или internal.
+    # Связана с видимостью ролей: internal пермишены не должны входить в public роли.
+    visibility: public
+    
+    # Здесь задаются условия, когда пермишен может действовать.
+    allowedWhen:
+      
+      # Сейчас можно задать только условие на статус клауда.
+      cloud:
+        status:
+        - BLOCKED_BY_BILLING
+        - ACTIVE
+      # Этим пермишеном можно воспользоваться только тогда, когда клауд
+      # находится в статусе ACTIVE или BLOCKED_BY_BILLING.
+      # А если клауд в другом статусе — например, BLOCKED — пермишен запрещён.
+```

Some files were not shown because too many files changed in this diff