os_policy.proto 20 KB

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