[{"data":1,"prerenderedAt":33},["ShallowReactive",2],{"doc:en:plugins\u002Fproject-credentials":3},{"title":4,"lede":5,"html":6,"headings":7},"Credentials per project","A VPN tunnel per project, end to end: the manifest, what the user sees, what the plugin reads, what .escouade.yml can and cannot do, the programs it runs and what is refused.","\u003Ch2 id=\"what-we-want\">What we want\u003C\u002Fh2>\n\u003Cp>A plugin opens, for each project, a tunnel to its client’s network. Two projects of the same client share a server and credentials; a third one has others. Three tools of Escouade 2.2.5 make it possible:\u003C\u002Fp>\n\u003Cul>\n\u003Cli>\u003Cstrong>a profile\u003C\u002Fstrong> (\u003Ccode class=\"key\">contributes.profiles\u003C\u002Fcode>): a server, a login, a password, an OpenVPN configuration, which the user creates as many times as they want on the plugin’s page;\u003C\u002Fli>\n\u003Cli>\u003Cstrong>a setting of each project\u003C\u002Fstrong> (\u003Ccode>&quot;scope&quot;: &quot;project&quot;\u003C\u002Fcode>): the profile this project takes, and its routes;\u003C\u002Fli>\n\u003Cli>\u003Cstrong>jokers\u003C\u002Fstrong> in \u003Ccode class=\"key\">permissions.commands\u003C\u002Fcode> and \u003Cstrong>a limit of programs\u003C\u002Fstrong> (\u003Ccode class=\"key\">limits.processes\u003C\u002Fcode>): the programs of the tunnel, each word that varies checked by the host.\u003C\u002Fli>\n\u003C\u002Ful>\n\u003Cp>A secret has no project scope: a secret of \u003Ccode>&quot;scope&quot;: &quot;project&quot;\u003C\u002Fcode> is read, but the plugin stays disabled. A project’s credentials go through a profile, which several projects can share.\u003C\u002Fp>\n\u003Ch2 id=\"the-manifest\">The manifest\u003C\u002Fh2>\n\u003Cpre>\u003Ccode class=\"language-json\">{\n  &quot;id&quot;: &quot;dev.exemple.tunnel&quot;,\n  &quot;name&quot;: &quot;Tunnel&quot;,\n  &quot;version&quot;: &quot;1.0.0&quot;,\n  &quot;escouade&quot;: { &quot;api&quot;: &quot;1&quot;, &quot;min&quot;: &quot;2.2.5&quot; },\n  &quot;run&quot;: { &quot;js&quot;: &quot;dist\u002Fplugin.mjs&quot; },\n  &quot;activation&quot;: [&quot;event:agent.created&quot;],\n  &quot;permissions&quot;: {\n    &quot;events&quot;: [&quot;agent.created&quot;],\n    &quot;secrets&quot;: [&quot;profile:vpn&quot;],\n    &quot;files&quot;: [{ &quot;root&quot;: &quot;temp&quot;, &quot;access&quot;: &quot;write&quot; }],\n    &quot;commands&quot;: [\n      &quot;unshare -Urn openvpn --config {path:temp} --script-security 1&quot;,\n      &quot;slirp4netns --configure --mtu=65520 {pid} tap0&quot;\n    ]\n  },\n  &quot;limits&quot;: { &quot;processes&quot;: 8, &quot;reason&quot;: { &quot;fr&quot;: &quot;Deux programmes par tunnel, un tunnel par projet.&quot;, &quot;en&quot;: &quot;Two programs a tunnel, a tunnel a project.&quot; } },\n  &quot;contributes&quot;: {\n    &quot;profiles&quot;: [{\n      &quot;id&quot;: &quot;vpn&quot;,\n      &quot;title&quot;: { &quot;fr&quot;: &quot;Profil VPN&quot;, &quot;en&quot;: &quot;VPN profile&quot; },\n      &quot;nameField&quot;: &quot;name&quot;,\n      &quot;fields&quot;: [\n        { &quot;key&quot;: &quot;name&quot;, &quot;type&quot;: &quot;string&quot;, &quot;title&quot;: { &quot;fr&quot;: &quot;Nom du profil&quot;, &quot;en&quot;: &quot;Profile name&quot; } },\n        { &quot;key&quot;: &quot;server&quot;, &quot;type&quot;: &quot;string&quot;, &quot;title&quot;: { &quot;fr&quot;: &quot;Serveur&quot;, &quot;en&quot;: &quot;Server&quot; } },\n        { &quot;key&quot;: &quot;proto&quot;, &quot;type&quot;: &quot;select&quot;, &quot;title&quot;: { &quot;fr&quot;: &quot;Protocole&quot;, &quot;en&quot;: &quot;Protocol&quot; }, &quot;options&quot;: [&quot;udp&quot;, &quot;tcp&quot;], &quot;default&quot;: &quot;udp&quot; },\n        { &quot;key&quot;: &quot;password&quot;, &quot;secret&quot;: true, &quot;title&quot;: { &quot;fr&quot;: &quot;Mot de passe&quot;, &quot;en&quot;: &quot;Password&quot; } },\n        { &quot;key&quot;: &quot;ovpn&quot;, &quot;secret&quot;: true, &quot;multiline&quot;: true, &quot;import&quot;: [&quot;.ovpn&quot;, &quot;.conf&quot;], &quot;title&quot;: { &quot;fr&quot;: &quot;Configuration OpenVPN&quot;, &quot;en&quot;: &quot;OpenVPN configuration&quot; } }\n      ]\n    }],\n    &quot;settings&quot;: [\n      { &quot;key&quot;: &quot;profile&quot;, &quot;type&quot;: &quot;profile&quot;, &quot;of&quot;: &quot;vpn&quot;, &quot;scope&quot;: &quot;project&quot;, &quot;title&quot;: { &quot;fr&quot;: &quot;Profil VPN&quot;, &quot;en&quot;: &quot;VPN profile&quot; } },\n      { &quot;key&quot;: &quot;routes&quot;, &quot;type&quot;: &quot;string&quot;, &quot;scope&quot;: &quot;project&quot;, &quot;default&quot;: &quot;10.0.0.0\u002F8&quot;, &quot;title&quot;: { &quot;fr&quot;: &quot;Routes par le tunnel&quot;, &quot;en&quot;: &quot;Routes through the tunnel&quot; } }\n    ]\n  }\n}\n\u003C\u002Fcode>\u003C\u002Fpre>\n\u003Cul>\n\u003Cli>\u003Ccode class=\"key\">profile:vpn\u003C\u002Fcode> in \u003Ccode class=\"key\">permissions.secrets\u003C\u002Fcode> asks for the secrets of the profiles of the kind \u003Ccode class=\"key\">vpn\u003C\u002Fcode>; without it, \u003Ccode class=\"key\">secrets\u002Fget\u003C\u002Fcode> refuses them (\u003Ccode class=\"key\">-32001\u003C\u002Fcode>).\u003C\u002Fli>\n\u003Cli>\u003Ccode class=\"key\">nameField\u003C\u002Fcode> names the field that gives the profile its name, in the lists.\u003C\u002Fli>\n\u003Cli>\u003Ccode class=\"key\">multiline\u003C\u002Fcode> and \u003Ccode class=\"key\">import\u003C\u002Fcode> make the configuration an area of several lines, pasted or imported from a file read once.\u003C\u002Fli>\n\u003Cli>\u003Ccode class=\"key\">escouade.min\u003C\u002Fcode> says \u003Ccode class=\"key\">2.2.5\u003C\u002Fcode>: an older Escouade serves neither the profiles, nor the jokers, nor the limit (\u003Ca href=\"\u002Fen\u002Fdocs\u002Fplugins\u002Fversioning\u002F#the-contract-of-2-2-5\">versioning\u003C\u002Fa>).\u003C\u002Fli>\n\u003C\u002Ful>\n\u003Ch2 id=\"what-the-user-sees\">What the user sees\u003C\u002Fh2>\n\u003Cul>\n\u003Cli>\u003Cstrong>At the installation\u003C\u002Fstrong>, the window shows each command, each joker as a pill of words (“a file of its temporary folder”, “a program it started”), then “Up to 8 programs at once”, “4 without asking” and the author’s reason.\u003C\u002Fli>\n\u003Cli>\u003Cstrong>On the plugin’s page\u003C\u002Fstrong>, “Settings” tab: “VPN profile”, “Add a profile…”. Each profile opens in a window, its simple fields then its secrets; the configuration is pasted or imported (“Import a file…”). Once kept, a secret is not read back: “Kept · 84 lines · 5.1 KB”, “Replace…”, “Forget”.\u003C\u002Fli>\n\u003Cli>\u003Cstrong>In Settings › Projects › \u003Cem>project\u003C\u002Fem> › Plugins\u003C\u002Fstrong>, each project chooses its profile and sets its routes. Deleting a profile erases its secrets, and the projects that took it go to “No profile”.\u003C\u002Fli>\n\u003C\u002Ful>\n\u003Ch2 id=\"what-the-plugin-reads\">What the plugin reads\u003C\u002Fh2>\n\u003Cp>A project’s profile is a setting like any other: \u003Ccode class=\"key\">settings\u002Fget\u003C\u002Fcode> of that project gives its id, drawn by Escouade, or \u003Ccode class=\"key\">null\u003C\u002Fcode> while it chose none. The plugin then reads the profile’s simple fields (\u003Ccode class=\"key\">profiles\u002Fget\u003C\u002Fcode>) and its secrets (\u003Ccode class=\"key\">secrets\u002Fget\u003C\u002Fcode> with \u003Ccode class=\"key\">profile\u003C\u002Fcode>):\u003C\u002Fp>\n\u003Cp>\u003Ccode>sdk\u002Fdoc-examples\u002Fts\u002Fsrc\u002Fprofiles.ts\u003C\u002Fcode> (excerpt)\u003C\u002Fp>\n\u003Cpre>\u003Ccode class=\"language-ts\">\u002F\u002F The profile the project chose (a `profile` setting of `&quot;scope&quot;: &quot;project&quot;`): its id, or null while it chose none.\n\u002F\u002F Only the user chooses it, never a `.escouade.yml`.\nexport function profileOf(p: Plugin, project: string) {\n  return p.profiles.of(project, &#39;profile&#39;);\n}\n\n\u002F\u002F Its simple fields, then its secrets: a configuration on several lines comes whole.\nexport async function credentials(p: Plugin, profile: string) {\n  const fields = await p.profiles.get(&#39;vpn&#39;, profile);\n  const password = await p.secret(&#39;password&#39;, { profile });\n  const ovpn = await p.secret(&#39;ovpn&#39;, { profile });\n  return { server: fields?.server, password, ovpn };\n}\n\u003C\u002Fcode>\u003C\u002Fpre>\n\u003Cp>A setting of each project is read the same way, by its ranks: this machine’s value for the project, else its \u003Ccode class=\"key\">.escouade.yml\u003C\u002Fcode>’s, else the manifest’s \u003Ccode class=\"key\">default\u003C\u002Fcode>.\u003C\u002Fp>\n\u003Cp>\u003Ccode>sdk\u002Fdoc-examples\u002Fts\u002Fsrc\u002Fprofiles.ts\u003C\u002Fcode> (excerpt)\u003C\u002Fp>\n\u003Cpre>\u003Ccode class=\"language-ts\">\u002F\u002F A setting of each project: this machine&#39;s value for it, else its `.escouade.yml`&#39;s, else the default.\nexport async function routes(p: Plugin, project: string) {\n  const settings = await p.settings(project);\n  return settings.routes;\n}\n\u003C\u002Fcode>\u003C\u002Fpre>\n\u003Cp>In Rust, the same calls:\u003C\u002Fp>\n\u003Cp>\u003Ccode>sdk\u002Fdoc-examples\u002Frust\u002Fsrc\u002Fprofiles.rs\u003C\u002Fcode> (excerpt)\u003C\u002Fp>\n\u003Cpre>\u003Ccode class=\"language-rust\">\u002F\u002F\u002F The profile the project chose (a `profile` setting of `&quot;scope&quot;: &quot;project&quot;`): its id, none while it chose none.\npub async fn profile_of(cx: &amp;Cx, project: &amp;str) -&gt; Result&lt;Option&lt;String&gt;, Refusal&gt; {\n    let settings = cx\n        .request(&quot;settings\u002Fget&quot;, json!({ &quot;project&quot;: project }))\n        .await?;\n    Ok(settings[&quot;profile&quot;].as_str().map(str::to_string))\n}\n\n\u002F\u002F\u002F A secret field of that profile: a configuration on several lines comes whole.\npub async fn secret_of(cx: &amp;Cx, profile: &amp;str, key: &amp;str) -&gt; Result&lt;Option&lt;String&gt;, Refusal&gt; {\n    let v = cx\n        .request(&quot;secrets\u002Fget&quot;, json!({ &quot;key&quot;: key, &quot;profile&quot;: profile }))\n        .await?;\n    Ok(v.as_str().map(str::to_string))\n}\n\u003C\u002Fcode>\u003C\u002Fpre>\n\u003Cp>The kit 0.1.4 names them \u003Ccode class=\"key\">Cx::profile_of\u003C\u002Fcode>, \u003Ccode class=\"key\">Cx::secret_of\u003C\u002Fcode>, \u003Ccode class=\"key\">Cx::profiles\u003C\u002Fcode>, \u003Ccode class=\"key\">Cx::profile\u003C\u002Fcode> and \u003Ccode class=\"key\">Cx::settings\u003C\u002Fcode> (\u003Ca href=\"\u002Fen\u002Fdocs\u002Fplugins\u002Frust\u002F#profiles-and-the-settings-of-a-project\">the Rust kit\u003C\u002Fa>).\u003C\u002Fp>\n\u003Cp>One instance serves all the projects of the plugin: it is its code that uses the profile of atlas-web only for atlas-web, and the store’s review reads it. The journal says \u003Ccode>was given its secret &quot;password&quot; of profile &quot;Client A&quot;\u003C\u002Fcode>, never the value; of a secret on several lines, it masks each line of more than 8 characters.\u003C\u002Fp>\n\u003Ch2 id=\"what-escouade-yml-can-and-cannot-do\">What \u003Ccode class=\"key\">.escouade.yml\u003C\u002Fcode> can and cannot do\u003C\u002Fh2>\n\u003Cp>A repository cloned from anyone must not choose the network your agents go through. What its \u003Ccode class=\"key\">.escouade.yml\u003C\u002Fcode> gives the plugin, under \u003Ccode class=\"key\">plugins.&lt;id&gt;\u003C\u002Fcode>:\u003C\u002Fp>\n\u003Cpre>\u003Ccode class=\"language-yaml\">plugins:\n  dev.exemple.tunnel:\n    routes: 10.20.0.0\u002F16\n    profile: client-a\n\u003C\u002Fcode>\u003C\u002Fpre>\n\u003Cul>\n\u003Cli>\u003Cstrong>A simple setting of \u003Ccode class=\"key\">project\u003C\u002Fcode> scope\u003C\u002Fstrong> (\u003Ccode class=\"key\">routes\u003C\u002Fcode>): yes. This machine’s value comes first; “Write into .escouade.yml”, on the project’s Plugins page, writes that key alone.\u003C\u002Fli>\n\u003Cli>\u003Cstrong>A profile\u003C\u002Fstrong>: never chosen. \u003Ccode>profile: client-a\u003C\u002Fcode> is only a proposal by a name: the project’s page says it in a band (“.escouade.yml proposes the profile “client-a” for Tunnel.”) and the user chooses.\u003C\u002Fli>\n\u003Cli>\u003Cstrong>A secret, a value imported from a file, a \u003Ccode>&quot;repo&quot;: false\u003C\u002Fcode> setting\u003C\u002Fstrong>: never. A secret key of the file is ignored.\u003C\u002Fli>\n\u003Cli>\u003Cstrong>Nothing, for a project where the plugin is not on\u003C\u002Fstrong> (turned off for that project, or a private project where it was not turned on): only the defaults, and \u003Ccode class=\"key\">null\u003C\u002Fcode> for a profile.\u003C\u002Fli>\n\u003C\u002Ful>\n\u003Ch2 id=\"the-programs-of-the-tunnel\">The programs of the tunnel\u003C\u002Fh2>\n\u003Cp>The plugin writes the configuration in its temporary folder, then runs the tunnel: \u003Ccode class=\"key\">{path:temp}\u003C\u002Fcode> is that file, \u003Ccode class=\"key\">{pid}\u003C\u002Fcode> the first program.\u003C\u002Fp>\n\u003Cp>\u003Ccode>sdk\u002Fdoc-examples\u002Fts\u002Fsrc\u002Fprofiles.ts\u003C\u002Fcode> (excerpt)\u003C\u002Fp>\n\u003Cpre>\u003Ccode class=\"language-ts\">\u002F\u002F The configuration in its temporary folder, then the tunnel: `{path:temp}` is that file, `{pid}` the first program.\nexport async function tunnel(p: Plugin, ovpn: string) {\n  await p.fs.write({ root: &#39;temp&#39;, path: &#39;tunnel.ovpn&#39;, text: ovpn });\n  const vpn = await p.runTyped({ command: &#39;unshare&#39;, args: [&#39;-Urn&#39;, &#39;openvpn&#39;, &#39;--config&#39;, &#39;tunnel.ovpn&#39;, &#39;--script-security&#39;, &#39;1&#39;] });\n  const net = await p.runTyped({ command: &#39;slirp4netns&#39;, args: [&#39;--configure&#39;, &#39;--mtu=65520&#39;, String(vpn.pid), &#39;tap0&#39;] });\n  return [vpn, net];\n}\n\u003C\u002Fcode>\u003C\u002Fpre>\n\u003Cul>\n\u003Cli>\u003Cstrong>\u003Ccode class=\"key\">{path:temp}\u003C\u002Fcode>\u003C\u002Fstrong>: the plugin gives \u003Ccode class=\"key\">tunnel.ovpn\u003C\u002Fcode>, the host resolves it under its temporary folder, checks it is a file that stays there, and gives the program its absolute path.\u003C\u002Fli>\n\u003Cli>\u003Cstrong>\u003Ccode class=\"key\">{pid}\u003C\u002Fcode>\u003C\u002Fstrong>: the pid of a living program this instance started; \u003Ccode class=\"key\">proc\u002Fspawn\u003C\u002Fcode> gives it with \u003Ccode class=\"key\">proc\u003C\u002Fcode> (\u003Ccode class=\"key\">p.runTyped\u003C\u002Fcode> and \u003Ccode class=\"key\">Cx::spawn_typed\u003C\u002Fcode> require it).\u003C\u002Fli>\n\u003Cli>\u003Cstrong>\u003Ccode>--script-security 1\u003C\u002Fcode> after \u003Ccode class=\"key\">--config\u003C\u002Fcode>\u003C\u002Fstrong>: OpenVPN takes the last value of an option given twice, which forbids the scripts the configuration would ask for. Check it on your version of OpenVPN: the review reads it.\u003C\u002Fli>\n\u003Cli>\u003Cstrong>Eight programs at once\u003C\u002Fstrong>: two a tunnel, four tunnels. The ninth is refused until one has ended: “8 programs at once at most for this plugin (limits.processes)”.\u003C\u002Fli>\n\u003C\u002Ful>\n\u003Ch2 id=\"what-is-refused\">What is refused\u003C\u002Fh2>\n\u003Cdiv class=\"table\">\u003Ctable>\n\u003Cthead>\n\u003Ctr>\n\u003Cth>What the plugin asks\u003C\u002Fth>\n\u003Cth>What Escouade says\u003C\u002Fth>\n\u003C\u002Ftr>\n\u003C\u002Fthead>\n\u003Ctbody>\u003Ctr>\n\u003Ctd>A secret of a profile without \u003Ccode class=\"key\">profile\u003C\u002Fcode> (\u003Ccode>secrets\u002Fget { &quot;key&quot;: &quot;password&quot; }\u003C\u002Fcode>)\u003C\u002Ftd>\n\u003Ctd>\u003Ccode class=\"key\">-32602\u003C\u002Fcode>: a field of a profile is asked with its profile, never another secret in its place\u003C\u002Ftd>\n\u003C\u002Ftr>\n\u003Ctr>\n\u003Ctd>A profile it does not have, or an id that is none\u003C\u002Ftd>\n\u003Ctd>\u003Ccode class=\"key\">-32602\u003C\u002Fcode>\u003C\u002Ftd>\n\u003C\u002Ftr>\n\u003Ctr>\n\u003Ctd>A field that is no secret of that kind\u003C\u002Ftd>\n\u003Ctd>\u003Ccode class=\"key\">-32602\u003C\u002Fcode>\u003C\u002Ftd>\n\u003C\u002Ftr>\n\u003Ctr>\n\u003Ctd>The secrets of a kind without \u003Ccode class=\"key\">profile:&lt;kind&gt;\u003C\u002Fcode> in its permissions\u003C\u002Ftd>\n\u003Ctd>\u003Ccode class=\"key\">-32001\u003C\u002Fcode>\u003C\u002Ftd>\n\u003C\u002Ftr>\n\u003Ctr>\n\u003Ctd>A word that does not have the form of its joker: an option (\u003Ccode class=\"key\">-x\u003C\u002Fcode>), \u003Ccode class=\"key\">..\u003C\u002Fcode>, an absolute path, a pid of another process\u003C\u002Ftd>\n\u003Ctd>\u003Ccode class=\"key\">-32003\u003C\u002Fcode>, the faulty word and the reason in the journal\u003C\u002Ftd>\n\u003C\u002Ftr>\n\u003Ctr>\n\u003Ctd>One program more than \u003Ccode class=\"key\">limits.processes\u003C\u002Fcode>\u003C\u002Ftd>\n\u003Ctd>\u003Ccode class=\"key\">-32003\u003C\u002Fcode>, the limit said\u003C\u002Ftd>\n\u003C\u002Ftr>\n\u003C\u002Ftbody>\u003C\u002Ftable>\u003C\u002Fdiv>\n\u003Cp>In the manifest, \u003Ccode>escouade-plugin validate\u003C\u002Fcode> says the faulty field and why (\u003Ca href=\"\u002Fen\u002Fdocs\u002Fplugins\u002Fcapabilities\u002F#the-jokers\">the jokers\u003C\u002Fa>).\u003C\u002Fp>\n\u003Ch2 id=\"test-it\">Test it\u003C\u002Fh2>\n\u003Cul>\n\u003Cli>\u003Cstrong>The bench\u003C\u002Fstrong> (\u003Ccode>escouade-plugin test .\u003C\u002Fcode>) plays one profile by kind, chosen by the bench’s project, secrets on several lines, and runs the programs for real. Its scenarios “Profiles”, “Multi-line secret”, “Command jokers” and “Program limit” say what was refused (\u003Ca href=\"\u002Fen\u002Fdocs\u002Fplugins\u002Ftesting\u002F#the-conformance-bench\">testing a plugin\u003C\u002Fa>).\u003C\u002Fli>\n\u003Cli>\u003Cstrong>The fake Escouade\u003C\u002Fstrong> of the SDK, given the manifest, serves the profiles, the settings of each project, the jokers and the limit as the app does (\u003Ca href=\"\u002Fen\u002Fdocs\u002Fplugins\u002Fsdk\u002F#the-tests\">the tests\u003C\u002Fa>).\u003C\u002Fli>\n\u003C\u002Ful>\n",[8,12,15,18,21,24,27,30],{"id":9,"text":10,"depth":11},"what-we-want","What we want",2,{"id":13,"text":14,"depth":11},"the-manifest","The manifest",{"id":16,"text":17,"depth":11},"what-the-user-sees","What the user sees",{"id":19,"text":20,"depth":11},"what-the-plugin-reads","What the plugin reads",{"id":22,"text":23,"depth":11},"what-escouade-yml-can-and-cannot-do","What .escouade.yml can and cannot do",{"id":25,"text":26,"depth":11},"the-programs-of-the-tunnel","The programs of the tunnel",{"id":28,"text":29,"depth":11},"what-is-refused","What is refused",{"id":31,"text":32,"depth":11},"test-it","Test it",1795952885578]