os_policy.proto 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445
  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.agentendpoint.v1;
  16. import "google/api/field_behavior.proto";
  17. option go_package = "google.golang.org/genproto/googleapis/cloud/osconfig/agentendpoint/v1;agentendpoint";
  18. option java_multiple_files = true;
  19. option java_outer_classname = "OSPolicyProto";
  20. option java_package = "com.google.cloud.osconfig.agentendpoint.v1";
  21. // An OS policy defines the desired state configuration for an instance.
  22. message OSPolicy {
  23. // Policy mode
  24. enum Mode {
  25. // Invalid mode
  26. MODE_UNSPECIFIED = 0;
  27. // This mode checks if the configuration resources in the policy are in
  28. // their desired state. No actions are performed if they are not in the
  29. // desired state. This mode is used for reporting purposes.
  30. VALIDATION = 1;
  31. // This mode checks if the configuration resources in the policy are in
  32. // their desired state, and if not, enforces the desired state.
  33. ENFORCEMENT = 2;
  34. }
  35. // An OS policy resource is used to define the desired state configuration
  36. // and provides a specific functionality like installing/removing packages,
  37. // executing a script etc.
  38. //
  39. // The system ensures that resources are always in their desired state by
  40. // taking necessary actions if they have drifted from their desired state.
  41. message Resource {
  42. // A remote or local file.
  43. message File {
  44. // Specifies a file available via some URI.
  45. message Remote {
  46. // Required. URI from which to fetch the object. It should contain both the
  47. // protocol and path following the format `{protocol}://{location}`.
  48. string uri = 1 [(google.api.field_behavior) = REQUIRED];
  49. // SHA256 checksum of the remote file.
  50. string sha256_checksum = 2;
  51. }
  52. // Specifies a file available as a Cloud Storage Object.
  53. message Gcs {
  54. // Required. Bucket of the Cloud Storage object.
  55. string bucket = 1 [(google.api.field_behavior) = REQUIRED];
  56. // Required. Name of the Cloud Storage object.
  57. string object = 2 [(google.api.field_behavior) = REQUIRED];
  58. // Generation number of the Cloud Storage object.
  59. int64 generation = 3;
  60. }
  61. // A specific type of file.
  62. oneof type {
  63. // A generic remote file.
  64. Remote remote = 1;
  65. // A Cloud Storage object.
  66. Gcs gcs = 2;
  67. // A local path to use.
  68. string local_path = 3;
  69. }
  70. // Defaults to false. When false, files are subject to validations
  71. // based on the file type:
  72. //
  73. // Remote: A checksum must be specified.
  74. // Cloud Storage: An object generation number must be specified.
  75. bool allow_insecure = 4;
  76. }
  77. // A resource that manages a system package.
  78. message PackageResource {
  79. // The desired state that the OS Config agent maintains on the VM.
  80. enum DesiredState {
  81. // Unspecified is invalid.
  82. DESIRED_STATE_UNSPECIFIED = 0;
  83. // Ensure that the package is installed.
  84. INSTALLED = 1;
  85. // The agent ensures that the package is not installed and
  86. // uninstalls it if detected.
  87. REMOVED = 2;
  88. }
  89. // A deb package file. dpkg packages only support INSTALLED state.
  90. message Deb {
  91. // Required. A deb package.
  92. File source = 1 [(google.api.field_behavior) = REQUIRED];
  93. // Whether dependencies should also be installed.
  94. // install when false: `dpkg -i package`
  95. // install when true: `apt-get update && apt-get -y install
  96. // package.deb`
  97. bool pull_deps = 2;
  98. }
  99. // A package managed by APT.
  100. // install: `apt-get update && apt-get -y install [name]`
  101. // remove: `apt-get -y remove [name]`
  102. message APT {
  103. // Required. Package name.
  104. string name = 1 [(google.api.field_behavior) = REQUIRED];
  105. }
  106. // An RPM package file. RPM packages only support INSTALLED state.
  107. message RPM {
  108. // Required. An rpm package.
  109. File source = 1 [(google.api.field_behavior) = REQUIRED];
  110. // Whether dependencies should also be installed.
  111. // install when false: `rpm --upgrade --replacepkgs package.rpm`
  112. // install when true: `yum -y install package.rpm` or
  113. // `zypper -y install package.rpm`
  114. bool pull_deps = 2;
  115. }
  116. // A package managed by YUM.
  117. // install: `yum -y install package`
  118. // remove: `yum -y remove package`
  119. message YUM {
  120. // Required. Package name.
  121. string name = 1 [(google.api.field_behavior) = REQUIRED];
  122. }
  123. // A package managed by Zypper.
  124. // install: `zypper -y install package`
  125. // remove: `zypper -y rm package`
  126. message Zypper {
  127. // Required. Package name.
  128. string name = 1 [(google.api.field_behavior) = REQUIRED];
  129. }
  130. // A package managed by GooGet.
  131. // install: `googet -noconfirm install package`
  132. // remove: `googet -noconfirm remove package`
  133. message GooGet {
  134. // Required. Package name.
  135. string name = 1 [(google.api.field_behavior) = REQUIRED];
  136. }
  137. // An MSI package. MSI packages only support INSTALLED state.
  138. message MSI {
  139. // Required. The MSI package.
  140. File source = 1 [(google.api.field_behavior) = REQUIRED];
  141. // Additional properties to use during installation.
  142. // This should be in the format of Property=Setting.
  143. // Appended to the defaults of "ACTION=INSTALL
  144. // REBOOT=ReallySuppress".
  145. repeated string properties = 2;
  146. }
  147. // Required. The desired state the agent should maintain for this package. The
  148. // default is to ensure the package is installed.
  149. DesiredState desired_state = 1 [(google.api.field_behavior) = REQUIRED];
  150. // A system package.
  151. oneof system_package {
  152. // A package managed by Apt.
  153. APT apt = 2;
  154. // A deb package file.
  155. Deb deb = 3;
  156. // A package managed by YUM.
  157. YUM yum = 4;
  158. // A package managed by Zypper.
  159. Zypper zypper = 5;
  160. // An rpm package file.
  161. RPM rpm = 6;
  162. // A package managed by GooGet.
  163. GooGet googet = 7;
  164. // An MSI package.
  165. MSI msi = 8;
  166. }
  167. }
  168. // A resource that manages a package repository.
  169. message RepositoryResource {
  170. // Represents a single apt package repository. These will be added to
  171. // a repo file that will be managed at
  172. // /etc/apt/sources.list.d/google_osconfig.list.
  173. message AptRepository {
  174. // Type of archive.
  175. enum ArchiveType {
  176. // Unspecified is invalid.
  177. ARCHIVE_TYPE_UNSPECIFIED = 0;
  178. // Deb indicates that the archive contains binary files.
  179. DEB = 1;
  180. // Deb-src indicates that the archive contains source files.
  181. DEB_SRC = 2;
  182. }
  183. // Required. Type of archive files in this repository. The default behavior is
  184. // DEB.
  185. ArchiveType archive_type = 1 [(google.api.field_behavior) = REQUIRED];
  186. // Required. URI for this repository.
  187. string uri = 2 [(google.api.field_behavior) = REQUIRED];
  188. // Required. Distribution of this repository.
  189. string distribution = 3 [(google.api.field_behavior) = REQUIRED];
  190. // Required. List of components for this repository. Must contain at least one
  191. // item.
  192. repeated string components = 4 [(google.api.field_behavior) = REQUIRED];
  193. // URI of the key file for this repository. The agent maintains a
  194. // keyring at /etc/apt/trusted.gpg.d/osconfig_agent_managed.gpg.
  195. string gpg_key = 5;
  196. }
  197. // Represents a single yum package repository. These are added to a
  198. // repo file that is managed at
  199. // `/etc/yum.repos.d/google_osconfig.repo`.
  200. message YumRepository {
  201. // Required. A one word, unique name for this repository. This is the `repo
  202. // id` in the yum config file and also the `display_name` if
  203. // `display_name` is omitted. This id is also used as the unique
  204. // identifier when checking for resource conflicts.
  205. string id = 1 [(google.api.field_behavior) = REQUIRED];
  206. // The display name of the repository.
  207. string display_name = 2;
  208. // Required. The location of the repository directory.
  209. string base_url = 3 [(google.api.field_behavior) = REQUIRED];
  210. // URIs of GPG keys.
  211. repeated string gpg_keys = 4;
  212. }
  213. // Represents a single zypper package repository. These are added to a
  214. // repo file that is managed at
  215. // `/etc/zypp/repos.d/google_osconfig.repo`.
  216. message ZypperRepository {
  217. // Required. A one word, unique name for this repository. This is the `repo
  218. // id` in the zypper config file and also the `display_name` if
  219. // `display_name` is omitted. This id is also used as the unique
  220. // identifier when checking for GuestPolicy conflicts.
  221. string id = 1 [(google.api.field_behavior) = REQUIRED];
  222. // The display name of the repository.
  223. string display_name = 2;
  224. // Required. The location of the repository directory.
  225. string base_url = 3 [(google.api.field_behavior) = REQUIRED];
  226. // URIs of GPG keys.
  227. repeated string gpg_keys = 4;
  228. }
  229. // Represents a Goo package repository. These are added to a repo file
  230. // that is managed at
  231. // `C:/ProgramData/GooGet/repos/google_osconfig.repo`.
  232. message GooRepository {
  233. // Required. The name of the repository.
  234. string name = 1 [(google.api.field_behavior) = REQUIRED];
  235. // Required. The url of the repository.
  236. string url = 2 [(google.api.field_behavior) = REQUIRED];
  237. }
  238. // A specific type of repository.
  239. oneof repository {
  240. // An Apt Repository.
  241. AptRepository apt = 1;
  242. // A Yum Repository.
  243. YumRepository yum = 2;
  244. // A Zypper Repository.
  245. ZypperRepository zypper = 3;
  246. // A Goo Repository.
  247. GooRepository goo = 4;
  248. }
  249. }
  250. // A resource that contains custom validation and enforcement steps.
  251. message ExecResource {
  252. // A file or script to execute.
  253. message Exec {
  254. // The interpreter to use.
  255. enum Interpreter {
  256. // Invalid value, the request will return validation error.
  257. INTERPRETER_UNSPECIFIED = 0;
  258. // If no interpreter is specified the
  259. // source will be executed directly, which will likely only
  260. // succeed for executables and scripts with shebang lines.
  261. // [Wikipedia
  262. // shebang](https://en.wikipedia.org/wiki/Shebang_(Unix)).
  263. NONE = 1;
  264. // Indicates that the script will be run with /bin/sh on Linux and
  265. // cmd.exe on windows.
  266. SHELL = 2;
  267. // Indicates that the script will be run with powershell.
  268. POWERSHELL = 3;
  269. }
  270. // What to execute.
  271. oneof source {
  272. // A remote or local file.
  273. File file = 1;
  274. // An inline script.
  275. string script = 2;
  276. }
  277. // Optional arguments to pass to the source during execution.
  278. repeated string args = 3;
  279. // Required. The script interpreter to use.
  280. Interpreter interpreter = 4 [(google.api.field_behavior) = REQUIRED];
  281. // Only recorded for enforce Exec.
  282. // Path to an output file (that is created by this Exec) whose
  283. // content will be recorded in OSPolicyResourceCompliance after a
  284. // successful run. Absence or failure to read this file will result in
  285. // this ExecResource being non-compliant. Output file size is limited to
  286. // 100K bytes.
  287. string output_file_path = 5;
  288. }
  289. // Required. What to run to validate this resource is in the desired state.
  290. // An exit code of 100 indicates "in desired state", and exit code of 101
  291. // indicates "not in desired state". Any other exit code indicates a
  292. // failure running validate.
  293. Exec validate = 1 [(google.api.field_behavior) = REQUIRED];
  294. // What to run to bring this resource into the desired state.
  295. // A exit code of 100 indicates "success", any other exit code idicates a
  296. // failure running enforce.
  297. Exec enforce = 2;
  298. }
  299. // A resource that manages the state of a file.
  300. message FileResource {
  301. // Desired state of the file.
  302. enum DesiredState {
  303. // Unspecified is invalid.
  304. DESIRED_STATE_UNSPECIFIED = 0;
  305. // Ensure file at path is present.
  306. PRESENT = 1;
  307. // Ensure file at path is absent.
  308. ABSENT = 2;
  309. // Ensure the contents of the file at path matches. If the file does
  310. // not exist it will be created.
  311. CONTENTS_MATCH = 3;
  312. }
  313. // The source for the contents of the file.
  314. oneof source {
  315. // A remote or local source.
  316. File file = 1;
  317. // A a file with this content.
  318. string content = 2;
  319. }
  320. // Required. The absolute path of the file.
  321. string path = 3 [(google.api.field_behavior) = REQUIRED];
  322. // Required. Desired state of the file.
  323. DesiredState state = 4 [(google.api.field_behavior) = REQUIRED];
  324. // Consists of three octal digits which represent, in
  325. // order, the permissions of the owner, group, and other users for the
  326. // file (similarly to the numeric mode used in the linux chmod
  327. // utility). Each digit represents a three bit number with the 4 bit
  328. // corresponding to the read permissions, the 2 bit corresponds to the
  329. // write bit, and the one bit corresponds to the execute permission.
  330. // Default behavior is 755.
  331. //
  332. // Below are some examples of permissions and their associated values:
  333. // read, write, and execute: 7
  334. // read and execute: 5
  335. // read and write: 6
  336. // read only: 4
  337. string permissions = 5;
  338. }
  339. // Required. The id of the resource with the following restrictions:
  340. //
  341. // * Must contain only lowercase letters, numbers, and hyphens.
  342. // * Must start with a letter.
  343. // * Must be between 1-63 characters.
  344. // * Must end with a number or a letter.
  345. // * Must be unique within the OS policy.
  346. string id = 1 [(google.api.field_behavior) = REQUIRED];
  347. // Resource type.
  348. oneof resource_type {
  349. // Package resource
  350. PackageResource pkg = 2;
  351. // Package repository resource
  352. RepositoryResource repository = 3;
  353. // Exec resource
  354. ExecResource exec = 4;
  355. // File resource
  356. FileResource file = 5;
  357. }
  358. }
  359. }