os_policy.proto 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565
  1. // Copyright 2021 Google LLC
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. syntax = "proto3";
  15. package google.cloud.osconfig.v1alpha;
  16. import "google/api/field_behavior.proto";
  17. option csharp_namespace = "Google.Cloud.OsConfig.V1Alpha";
  18. option go_package = "google.golang.org/genproto/googleapis/cloud/osconfig/v1alpha;osconfig";
  19. option java_multiple_files = true;
  20. option java_outer_classname = "OsPolicyProto";
  21. option java_package = "com.google.cloud.osconfig.v1alpha";
  22. option php_namespace = "Google\\Cloud\\OsConfig\\V1alpha";
  23. option ruby_package = "Google::Cloud::OsConfig::V1alpha";
  24. // An OS policy defines the desired state configuration for a VM.
  25. message OSPolicy {
  26. // Policy mode
  27. enum Mode {
  28. // Invalid mode
  29. MODE_UNSPECIFIED = 0;
  30. // This mode checks if the configuration resources in the policy are in
  31. // their desired state. No actions are performed if they are not in the
  32. // desired state. This mode is used for reporting purposes.
  33. VALIDATION = 1;
  34. // This mode checks if the configuration resources in the policy are in
  35. // their desired state, and if not, enforces the desired state.
  36. ENFORCEMENT = 2;
  37. }
  38. // Filtering criteria to select VMs based on OS details.
  39. message OSFilter {
  40. // This should match OS short name emitted by the OS inventory agent.
  41. // An empty value matches any OS.
  42. string os_short_name = 1;
  43. // This value should match the version emitted by the OS inventory
  44. // agent.
  45. // Prefix matches are supported if asterisk(*) is provided as the
  46. // last character. For example, to match all versions with a major
  47. // version of `7`, specify the following value for this field `7.*`
  48. string os_version = 2;
  49. }
  50. // Filtering criteria to select VMs based on inventory details.
  51. message InventoryFilter {
  52. // Required. The OS short name
  53. string os_short_name = 1 [(google.api.field_behavior) = REQUIRED];
  54. // The OS version
  55. //
  56. // Prefix matches are supported if asterisk(*) is provided as the
  57. // last character. For example, to match all versions with a major
  58. // version of `7`, specify the following value for this field `7.*`
  59. //
  60. // An empty string matches all OS versions.
  61. string os_version = 2;
  62. }
  63. // An OS policy resource is used to define the desired state configuration
  64. // and provides a specific functionality like installing/removing packages,
  65. // executing a script etc.
  66. //
  67. // The system ensures that resources are always in their desired state by
  68. // taking necessary actions if they have drifted from their desired state.
  69. message Resource {
  70. // A remote or local file.
  71. message File {
  72. // Specifies a file available via some URI.
  73. message Remote {
  74. // Required. URI from which to fetch the object. It should contain both the
  75. // protocol and path following the format `{protocol}://{location}`.
  76. string uri = 1 [(google.api.field_behavior) = REQUIRED];
  77. // SHA256 checksum of the remote file.
  78. string sha256_checksum = 2;
  79. }
  80. // Specifies a file available as a Cloud Storage Object.
  81. message Gcs {
  82. // Required. Bucket of the Cloud Storage object.
  83. string bucket = 1 [(google.api.field_behavior) = REQUIRED];
  84. // Required. Name of the Cloud Storage object.
  85. string object = 2 [(google.api.field_behavior) = REQUIRED];
  86. // Generation number of the Cloud Storage object.
  87. int64 generation = 3;
  88. }
  89. // A specific type of file.
  90. oneof type {
  91. // A generic remote file.
  92. Remote remote = 1;
  93. // A Cloud Storage object.
  94. Gcs gcs = 2;
  95. // A local path within the VM to use.
  96. string local_path = 3;
  97. }
  98. // Defaults to false. When false, files are subject to validations
  99. // based on the file type:
  100. //
  101. // Remote: A checksum must be specified.
  102. // Cloud Storage: An object generation number must be specified.
  103. bool allow_insecure = 4;
  104. }
  105. // A resource that manages a system package.
  106. message PackageResource {
  107. // The desired state that the OS Config agent maintains on the VM.
  108. enum DesiredState {
  109. // Unspecified is invalid.
  110. DESIRED_STATE_UNSPECIFIED = 0;
  111. // Ensure that the package is installed.
  112. INSTALLED = 1;
  113. // The agent ensures that the package is not installed and
  114. // uninstalls it if detected.
  115. REMOVED = 2;
  116. }
  117. // A deb package file. dpkg packages only support INSTALLED state.
  118. message Deb {
  119. // Required. A deb package.
  120. File source = 1 [(google.api.field_behavior) = REQUIRED];
  121. // Whether dependencies should also be installed.
  122. // - install when false: `dpkg -i package`
  123. // - install when true: `apt-get update && apt-get -y install
  124. // package.deb`
  125. bool pull_deps = 2;
  126. }
  127. // A package managed by APT.
  128. // - install: `apt-get update && apt-get -y install [name]`
  129. // - remove: `apt-get -y remove [name]`
  130. message APT {
  131. // Required. Package name.
  132. string name = 1 [(google.api.field_behavior) = REQUIRED];
  133. }
  134. // An RPM package file. RPM packages only support INSTALLED state.
  135. message RPM {
  136. // Required. An rpm package.
  137. File source = 1 [(google.api.field_behavior) = REQUIRED];
  138. // Whether dependencies should also be installed.
  139. // - install when false: `rpm --upgrade --replacepkgs package.rpm`
  140. // - install when true: `yum -y install package.rpm` or
  141. // `zypper -y install package.rpm`
  142. bool pull_deps = 2;
  143. }
  144. // A package managed by YUM.
  145. // - install: `yum -y install package`
  146. // - remove: `yum -y remove package`
  147. message YUM {
  148. // Required. Package name.
  149. string name = 1 [(google.api.field_behavior) = REQUIRED];
  150. }
  151. // A package managed by Zypper.
  152. // - install: `zypper -y install package`
  153. // - remove: `zypper -y rm package`
  154. message Zypper {
  155. // Required. Package name.
  156. string name = 1 [(google.api.field_behavior) = REQUIRED];
  157. }
  158. // A package managed by GooGet.
  159. // - install: `googet -noconfirm install package`
  160. // - remove: `googet -noconfirm remove package`
  161. message GooGet {
  162. // Required. Package name.
  163. string name = 1 [(google.api.field_behavior) = REQUIRED];
  164. }
  165. // An MSI package. MSI packages only support INSTALLED state.
  166. message MSI {
  167. // Required. The MSI package.
  168. File source = 1 [(google.api.field_behavior) = REQUIRED];
  169. // Additional properties to use during installation.
  170. // This should be in the format of Property=Setting.
  171. // Appended to the defaults of `ACTION=INSTALL
  172. // REBOOT=ReallySuppress`.
  173. repeated string properties = 2;
  174. }
  175. // Required. The desired state the agent should maintain for this package.
  176. DesiredState desired_state = 1 [(google.api.field_behavior) = REQUIRED];
  177. // A system package.
  178. oneof system_package {
  179. // A package managed by Apt.
  180. APT apt = 2;
  181. // A deb package file.
  182. Deb deb = 3;
  183. // A package managed by YUM.
  184. YUM yum = 4;
  185. // A package managed by Zypper.
  186. Zypper zypper = 5;
  187. // An rpm package file.
  188. RPM rpm = 6;
  189. // A package managed by GooGet.
  190. GooGet googet = 7;
  191. // An MSI package.
  192. MSI msi = 8;
  193. }
  194. }
  195. // A resource that manages a package repository.
  196. message RepositoryResource {
  197. // Represents a single apt package repository. These will be added to
  198. // a repo file that will be managed at
  199. // `/etc/apt/sources.list.d/google_osconfig.list`.
  200. message AptRepository {
  201. // Type of archive.
  202. enum ArchiveType {
  203. // Unspecified is invalid.
  204. ARCHIVE_TYPE_UNSPECIFIED = 0;
  205. // Deb indicates that the archive contains binary files.
  206. DEB = 1;
  207. // Deb-src indicates that the archive contains source files.
  208. DEB_SRC = 2;
  209. }
  210. // Required. Type of archive files in this repository.
  211. ArchiveType archive_type = 1 [(google.api.field_behavior) = REQUIRED];
  212. // Required. URI for this repository.
  213. string uri = 2 [(google.api.field_behavior) = REQUIRED];
  214. // Required. Distribution of this repository.
  215. string distribution = 3 [(google.api.field_behavior) = REQUIRED];
  216. // Required. List of components for this repository. Must contain at least one
  217. // item.
  218. repeated string components = 4 [(google.api.field_behavior) = REQUIRED];
  219. // URI of the key file for this repository. The agent maintains a
  220. // keyring at `/etc/apt/trusted.gpg.d/osconfig_agent_managed.gpg`.
  221. string gpg_key = 5;
  222. }
  223. // Represents a single yum package repository. These are added to a
  224. // repo file that is managed at
  225. // `/etc/yum.repos.d/google_osconfig.repo`.
  226. message YumRepository {
  227. // Required. A one word, unique name for this repository. This is the `repo
  228. // id` in the yum config file and also the `display_name` if
  229. // `display_name` is omitted. This id is also used as the unique
  230. // identifier when checking for resource conflicts.
  231. string id = 1 [(google.api.field_behavior) = REQUIRED];
  232. // The display name of the repository.
  233. string display_name = 2;
  234. // Required. The location of the repository directory.
  235. string base_url = 3 [(google.api.field_behavior) = REQUIRED];
  236. // URIs of GPG keys.
  237. repeated string gpg_keys = 4;
  238. }
  239. // Represents a single zypper package repository. These are added to a
  240. // repo file that is managed at
  241. // `/etc/zypp/repos.d/google_osconfig.repo`.
  242. message ZypperRepository {
  243. // Required. A one word, unique name for this repository. This is the `repo
  244. // id` in the zypper config file and also the `display_name` if
  245. // `display_name` is omitted. This id is also used as the unique
  246. // identifier when checking for GuestPolicy conflicts.
  247. string id = 1 [(google.api.field_behavior) = REQUIRED];
  248. // The display name of the repository.
  249. string display_name = 2;
  250. // Required. The location of the repository directory.
  251. string base_url = 3 [(google.api.field_behavior) = REQUIRED];
  252. // URIs of GPG keys.
  253. repeated string gpg_keys = 4;
  254. }
  255. // Represents a Goo package repository. These are added to a repo file
  256. // that is managed at
  257. // `C:/ProgramData/GooGet/repos/google_osconfig.repo`.
  258. message GooRepository {
  259. // Required. The name of the repository.
  260. string name = 1 [(google.api.field_behavior) = REQUIRED];
  261. // Required. The url of the repository.
  262. string url = 2 [(google.api.field_behavior) = REQUIRED];
  263. }
  264. // A specific type of repository.
  265. oneof repository {
  266. // An Apt Repository.
  267. AptRepository apt = 1;
  268. // A Yum Repository.
  269. YumRepository yum = 2;
  270. // A Zypper Repository.
  271. ZypperRepository zypper = 3;
  272. // A Goo Repository.
  273. GooRepository goo = 4;
  274. }
  275. }
  276. // A resource that allows executing scripts on the VM.
  277. //
  278. // The `ExecResource` has 2 stages: `validate` and `enforce` and both stages
  279. // accept a script as an argument to execute.
  280. //
  281. // When the `ExecResource` is applied by the agent, it first executes the
  282. // script in the `validate` stage. The `validate` stage can signal that the
  283. // `ExecResource` is already in the desired state by returning an exit code
  284. // of `100`. If the `ExecResource` is not in the desired state, it should
  285. // return an exit code of `101`. Any other exit code returned by this stage
  286. // is considered an error.
  287. //
  288. // If the `ExecResource` is not in the desired state based on the exit code
  289. // from the `validate` stage, the agent proceeds to execute the script from
  290. // the `enforce` stage. If the `ExecResource` is already in the desired
  291. // state, the `enforce` stage will not be run.
  292. // Similar to `validate` stage, the `enforce` stage should return an exit
  293. // code of `100` to indicate that the resource in now in its desired state.
  294. // Any other exit code is considered an error.
  295. //
  296. // NOTE: An exit code of `100` was chosen over `0` (and `101` vs `1`) to
  297. // have an explicit indicator of `in desired state`, `not in desired state`
  298. // and errors. Because, for example, Powershell will always return an exit
  299. // code of `0` unless an `exit` statement is provided in the script. So, for
  300. // reasons of consistency and being explicit, exit codes `100` and `101`
  301. // were chosen.
  302. message ExecResource {
  303. // A file or script to execute.
  304. message Exec {
  305. // The interpreter to use.
  306. enum Interpreter {
  307. // Invalid value, the request will return validation error.
  308. INTERPRETER_UNSPECIFIED = 0;
  309. // If an interpreter is not specified, the
  310. // source is executed directly. This execution, without an
  311. // interpreter, only succeeds for executables and scripts that have <a
  312. // href="https://en.wikipedia.org/wiki/Shebang_(Unix)"
  313. // class="external">shebang lines</a>.
  314. NONE = 1;
  315. // Indicates that the script runs with `/bin/sh` on Linux and
  316. // `cmd.exe` on Windows.
  317. SHELL = 2;
  318. // Indicates that the script runs with PowerShell.
  319. POWERSHELL = 3;
  320. }
  321. // What to execute.
  322. oneof source {
  323. // A remote or local file.
  324. File file = 1;
  325. // An inline script.
  326. // The size of the script is limited to 1024 characters.
  327. string script = 2;
  328. }
  329. // Optional arguments to pass to the source during execution.
  330. repeated string args = 3;
  331. // Required. The script interpreter to use.
  332. Interpreter interpreter = 4 [(google.api.field_behavior) = REQUIRED];
  333. // Only recorded for enforce Exec.
  334. // Path to an output file (that is created by this Exec) whose
  335. // content will be recorded in OSPolicyResourceCompliance after a
  336. // successful run. Absence or failure to read this file will result in
  337. // this ExecResource being non-compliant. Output file size is limited to
  338. // 100K bytes.
  339. string output_file_path = 5;
  340. }
  341. // Required. What to run to validate this resource is in the desired state.
  342. // An exit code of 100 indicates "in desired state", and exit code of 101
  343. // indicates "not in desired state". Any other exit code indicates a
  344. // failure running validate.
  345. Exec validate = 1 [(google.api.field_behavior) = REQUIRED];
  346. // What to run to bring this resource into the desired state.
  347. // An exit code of 100 indicates "success", any other exit code indicates
  348. // a failure running enforce.
  349. Exec enforce = 2;
  350. }
  351. // A resource that manages the state of a file.
  352. message FileResource {
  353. // Desired state of the file.
  354. enum DesiredState {
  355. // Unspecified is invalid.
  356. DESIRED_STATE_UNSPECIFIED = 0;
  357. // Ensure file at path is present.
  358. PRESENT = 1;
  359. // Ensure file at path is absent.
  360. ABSENT = 2;
  361. // Ensure the contents of the file at path matches. If the file does
  362. // not exist it will be created.
  363. CONTENTS_MATCH = 3;
  364. }
  365. // The source for the contents of the file.
  366. oneof source {
  367. // A remote or local source.
  368. File file = 1;
  369. // A a file with this content.
  370. // The size of the content is limited to 1024 characters.
  371. string content = 2;
  372. }
  373. // Required. The absolute path of the file within the VM.
  374. string path = 3 [(google.api.field_behavior) = REQUIRED];
  375. // Required. Desired state of the file.
  376. DesiredState state = 4 [(google.api.field_behavior) = REQUIRED];
  377. // Consists of three octal digits which represent, in
  378. // order, the permissions of the owner, group, and other users for the
  379. // file (similarly to the numeric mode used in the linux chmod
  380. // utility). Each digit represents a three bit number with the 4 bit
  381. // corresponding to the read permissions, the 2 bit corresponds to the
  382. // write bit, and the one bit corresponds to the execute permission.
  383. // Default behavior is 755.
  384. //
  385. // Below are some examples of permissions and their associated values:
  386. // read, write, and execute: 7
  387. // read and execute: 5
  388. // read and write: 6
  389. // read only: 4
  390. string permissions = 5;
  391. }
  392. // Required. The id of the resource with the following restrictions:
  393. //
  394. // * Must contain only lowercase letters, numbers, and hyphens.
  395. // * Must start with a letter.
  396. // * Must be between 1-63 characters.
  397. // * Must end with a number or a letter.
  398. // * Must be unique within the OS policy.
  399. string id = 1 [(google.api.field_behavior) = REQUIRED];
  400. // Resource type.
  401. oneof resource_type {
  402. // Package resource
  403. PackageResource pkg = 2;
  404. // Package repository resource
  405. RepositoryResource repository = 3;
  406. // Exec resource
  407. ExecResource exec = 4;
  408. // File resource
  409. FileResource file = 5;
  410. }
  411. }
  412. // Resource groups provide a mechanism to group OS policy resources.
  413. //
  414. // Resource groups enable OS policy authors to create a single OS policy
  415. // to be applied to VMs running different operating Systems.
  416. //
  417. // When the OS policy is applied to a target VM, the appropriate resource
  418. // group within the OS policy is selected based on the `OSFilter` specified
  419. // within the resource group.
  420. message ResourceGroup {
  421. // Deprecated. Use the `inventory_filters` field instead.
  422. // Used to specify the OS filter for a resource group
  423. OSFilter os_filter = 1 [deprecated = true];
  424. // List of inventory filters for the resource group.
  425. //
  426. // The resources in this resource group are applied to the target VM if it
  427. // satisfies at least one of the following inventory filters.
  428. //
  429. // For example, to apply this resource group to VMs running either `RHEL` or
  430. // `CentOS` operating systems, specify 2 items for the list with following
  431. // values:
  432. // inventory_filters[0].os_short_name='rhel' and
  433. // inventory_filters[1].os_short_name='centos'
  434. //
  435. // If the list is empty, this resource group will be applied to the target
  436. // VM unconditionally.
  437. repeated InventoryFilter inventory_filters = 3;
  438. // Required. List of resources configured for this resource group.
  439. // The resources are executed in the exact order specified here.
  440. repeated Resource resources = 2 [(google.api.field_behavior) = REQUIRED];
  441. }
  442. // Required. The id of the OS policy with the following restrictions:
  443. //
  444. // * Must contain only lowercase letters, numbers, and hyphens.
  445. // * Must start with a letter.
  446. // * Must be between 1-63 characters.
  447. // * Must end with a number or a letter.
  448. // * Must be unique within the assignment.
  449. string id = 1 [(google.api.field_behavior) = REQUIRED];
  450. // Policy description.
  451. // Length of the description is limited to 1024 characters.
  452. string description = 2;
  453. // Required. Policy mode
  454. Mode mode = 3 [(google.api.field_behavior) = REQUIRED];
  455. // Required. List of resource groups for the policy.
  456. // For a particular VM, resource groups are evaluated in the order specified
  457. // and the first resource group that is applicable is selected and the rest
  458. // are ignored.
  459. //
  460. // If none of the resource groups are applicable for a VM, the VM is
  461. // considered to be non-compliant w.r.t this policy. This behavior can be
  462. // toggled by the flag `allow_no_resource_group_match`
  463. repeated ResourceGroup resource_groups = 4 [(google.api.field_behavior) = REQUIRED];
  464. // This flag determines the OS policy compliance status when none of the
  465. // resource groups within the policy are applicable for a VM. Set this value
  466. // to `true` if the policy needs to be reported as compliant even if the
  467. // policy has nothing to validate or enforce.
  468. bool allow_no_resource_group_match = 5;
  469. }