<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[How to create additional postgresql role&#x27;s needed for an application?]]></title><description><![CDATA[<p dir="auto">I am working on packaging <a href="https://postgrest.org/en/v12/" target="_blank" rel="noopener noreferrer nofollow ugc">postgrest</a> and this application makes use of <a href="https://postgrest.org/en/v12/tutorials/tut0.html#:~:text=create%20role%20web_anon%20nologin%3B" target="_blank" rel="noopener noreferrer nofollow ugc">custom created roles</a> in postgres to implement its functionality.</p>
<p dir="auto">I have the app up and running but when I try to create a role from psql I get <code>ERROR:  permission denied to create role</code>.</p>
<p dir="auto">I tried looking through the <a href="https://git.cloudron.io/cloudron" target="_blank" rel="noopener noreferrer nofollow ugc">cloudron gitlab</a> to see if I could find any examples of another app that already does this but I didn't see any.</p>
<p dir="auto">It seems like <a href="https://git.cloudron.io/cloudron/postgresql-addon/-/blob/master/service.js?ref_type=heads" target="_blank" rel="noopener noreferrer nofollow ugc">this nodejs app</a> is what cloudron uses to interact with the postgresql instance it offers as a service when provisioning new databases for apps.</p>
<p dir="auto">This <a href="https://git.cloudron.io/cloudron/postgresql-addon/-/blob/master/service.js?ref_type=heads#L157" target="_blank" rel="noopener noreferrer nofollow ugc">function specifically</a> seems to be used when provisioning a new database for an app and it creates the role of the postgresql user that is created for the app being setup but doesn't seem to provide options for setting up additional roles that the application might need.</p>
<p dir="auto">I tried to search for <code>create role</code> across all the code in the cloudron gitlab and it doesn't appear to support searching for things in code unless you filter down to a specific project first so if there are other apps already that do this I am not sure how to find them using gitlab search.</p>
<p dir="auto">I also tried to use google search with <code>site:git.cloudron.io create role</code> but it looks like google is not indexing the content of that gitlab site which seems to be what is desired as the <a href="https://git.cloudron.io/robots.txt" target="_blank" rel="noopener noreferrer nofollow ugc">robots.txt</a> has <code>disallow: /</code>.</p>
<p dir="auto">Is there a method for getting whatever additional roles are needed setup during the application install so that permissions can stay the same but any custom roles that are needed can be setup by cloudron for the app to function?</p>
]]></description><link>https://forum.cloudron.io/topic/11331/how-to-create-additional-postgresql-role-s-needed-for-an-application</link><generator>RSS for Node</generator><lastBuildDate>Wed, 17 Jun 2026 13:47:53 GMT</lastBuildDate><atom:link href="https://forum.cloudron.io/topic/11331.rss" rel="self" type="application/rss+xml"/><pubDate>Sun, 17 Mar 2024 03:35:19 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to How to create additional postgresql role&#x27;s needed for an application? on Sat, 30 Mar 2024 11:48:13 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/christophermag" aria-label="Profile: ChristopherMag">@<bdi>ChristopherMag</bdi></a> great for exploring this further! Since roles are database global, installing/clone etc will cause conflicts. So, we have to have some elaborate scheme to accommodate this. This is quite complicated right now because only this specific app needs this. But TBF, if an app needs custom roles etc, it requires complete control of the database and Cloudron is probably not best suited for this at the moment.</p>
]]></description><link>https://forum.cloudron.io/post/86032</link><guid isPermaLink="true">https://forum.cloudron.io/post/86032</guid><dc:creator><![CDATA[girish]]></dc:creator><pubDate>Sat, 30 Mar 2024 11:48:13 GMT</pubDate></item><item><title><![CDATA[Reply to How to create additional postgresql role&#x27;s needed for an application? on Thu, 28 Mar 2024 18:13:05 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/girish" aria-label="Profile: girish">@<bdi>girish</bdi></a> Postgrest requires there to be something in the OIDC id_token that maps to the name of a role in the database.</p>
<p dir="auto">Here are the side effects of only being able to use <code>CLOUDRON_POSTGRESQL_USERNAME</code> with postgrest:</p>
<ul>
<li>All authenticated users would have the same permissions
<ul>
<li><a href="https://postgrest.org/en/v12/explanations/db_authz.html" target="_blank" rel="noopener noreferrer nofollow ugc">postgrest's permissions</a> are based on role permissions in the database</li>
<li>To have different different set's of permission requires have different roles available</li>
</ul>
</li>
<li>It currently isn't possible to use the value of <code>CLOUDRON_POSTGRESQL_USERNAME</code> as the role when using Cloudron's OIDC as the id_token jwt presented to postgrest needs to have a claim in it that maps to the name of the role in the database that user's permissions map to
<ul>
<li>From looking at <a href="https://git.cloudron.io/cloudron/box/-/blob/master/src/oidc.js" target="_blank" rel="noopener noreferrer nofollow ugc">oidc.js</a> I didn't see any code that would support adding custom claims that would be included in the id_token</li>
<li><a href="https://git.cloudron.io/cloudron/box/-/blob/master/src/oidc.js#L646" target="_blank" rel="noopener noreferrer nofollow ugc">Here is the specific spot in the codebase</a> that I think makes the claims for the id_token jwt</li>
<li>Ultimately this means someone would have to run an external OIDC provider like <a href="https://www.keycloak.org/" target="_blank" rel="noopener noreferrer nofollow ugc">keycloak</a> where they have more control over the claims in the jwt to be then able to make a claim that contains the value of <code>CLOUDRON_POSTGRESQL_USERNAME</code></li>
</ul>
</li>
</ul>
<p dir="auto">It feels like the easiest way to address this would be to enhance the <a href="https://git.cloudron.io/cloudron/postgresql-addon/-/blob/master/service.js?ref_type=heads#L157" target="_blank" rel="noopener noreferrer nofollow ugc">add function in the postgresql-addon</a> nodejs app to support taking in an array of roles the app needs and then executing something like the following pseudo code</p>
<pre><code>roles.foreach( role =&gt; function (role) {
    queries.push(`CREATE ROLE ${role} NOSUPERUSER NOCREATEDB NOCREATEROLE NOLOGIN`)
    queries.push(`GRANT ${role} TO ${username}`)
}
</code></pre>
<p dir="auto">Ps, I left off <code>NOINHERIT</code> as I believe inheritance would be needed to support having generic roles that are given permissions and then a role that corresponds to a specific user that is identified by sid in the jwt granted permissions to one of the generic roles.</p>
<p dir="auto">Then the roles array would be specified as an attribute of the <code>postgresql</code> addon key in the cloudron manifest:</p>
<pre><code>"postgresql": {
    "roles":["Role1CorrespondingtoUser1","Role2CorrespondingToUser2","GenericRole3","GenericRole4"]
}
</code></pre>
<p dir="auto">If your open to pull requests and you think this would make sense I could try to implement this.</p>
]]></description><link>https://forum.cloudron.io/post/85927</link><guid isPermaLink="true">https://forum.cloudron.io/post/85927</guid><dc:creator><![CDATA[ChristopherMag]]></dc:creator><pubDate>Thu, 28 Mar 2024 18:13:05 GMT</pubDate></item><item><title><![CDATA[Reply to How to create additional postgresql role&#x27;s needed for an application? on Mon, 25 Mar 2024 18:47:50 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/christophermag" aria-label="Profile: ChristopherMag">@<bdi>ChristopherMag</bdi></a> postgres roles are at the installation/cluster level , so this permission is not allowed for apps .</p>
<p dir="auto">When Cloudron provision postgresql for an app, it creates two roles - one with the same name as the database (CLOUDRON_POSTGRESQL_DATABASE) and now with same name as the username (CLOUDRON_POSTGRESQL_USERNAME). Maybe, you can use one of those already?</p>
]]></description><link>https://forum.cloudron.io/post/85710</link><guid isPermaLink="true">https://forum.cloudron.io/post/85710</guid><dc:creator><![CDATA[girish]]></dc:creator><pubDate>Mon, 25 Mar 2024 18:47:50 GMT</pubDate></item><item><title><![CDATA[Reply to How to create additional postgresql role&#x27;s needed for an application? on Sun, 24 Mar 2024 20:31:19 GMT]]></title><description><![CDATA[<p dir="auto">As a potential work around for this you can find the postgresql addon's root password by running the following on the cloudron server</p>
<p dir="auto"><code>sudo docker exec postgresql printenv CLOUDRON_POSTGRESQL_ROOT_PASSWORD</code></p>
<p dir="auto">I am assuming that using username root and this password I should be able to create the additional roles needed in the database for postgrest.</p>
]]></description><link>https://forum.cloudron.io/post/85637</link><guid isPermaLink="true">https://forum.cloudron.io/post/85637</guid><dc:creator><![CDATA[ChristopherMag]]></dc:creator><pubDate>Sun, 24 Mar 2024 20:31:19 GMT</pubDate></item></channel></rss>