mirror of
https://github.com/simonw/datasette.git
synced 2025-12-10 16:51:24 +01:00
allow_sql block to control execute-sql upermission in metadata.json, closes #813
Also removed the --config allow_sql:0 mechanism in favour of the new allow_sql block.
This commit is contained in:
parent
e0a4664fba
commit
49d6d2f7b0
16 changed files with 92 additions and 44 deletions
|
|
@ -176,7 +176,7 @@ This works for SQL views as well - you can treat them as if they are tables.
|
|||
.. warning::
|
||||
Restricting access to tables and views in this way will NOT prevent users from querying them using arbitrary SQL queries, `like this <https://latest.datasette.io/fixtures?sql=select+*+from+facetable>`__ for example.
|
||||
|
||||
If you are restricting access to specific tables you should also use the ``"allow_sql"`` block to prevent users from accessing
|
||||
If you are restricting access to specific tables you should also use the ``"allow_sql"`` block to prevent users from bypassing the limit with their own SQL queries - see :ref:`authentication_permissions_execute_sql`.
|
||||
|
||||
.. _authentication_permissions_query:
|
||||
|
||||
|
|
@ -203,6 +203,37 @@ To limit access to the ``add_name`` canned query in your ``dogs.db`` database to
|
|||
}
|
||||
}
|
||||
|
||||
.. _authentication_permissions_execute_sql:
|
||||
|
||||
Controlling the ability to execute arbitrary SQL
|
||||
------------------------------------------------
|
||||
|
||||
The ``"allow_sql"`` block can be used to control who is allowed to execute arbitrary SQL queries, both using the form on the database page e.g. https://latest.datasette.io/fixtures or by appending a ``?_where=`` parameter to the table page as seen on https://latest.datasette.io/fixtures/facetable?_where=city_id=1.
|
||||
|
||||
To enable just the :ref:`root user<authentication_root>` to execute SQL for all databases in your instance, use the following:
|
||||
|
||||
.. code-block:: json
|
||||
|
||||
{
|
||||
"allow_sql": {
|
||||
"id": "root"
|
||||
}
|
||||
}
|
||||
|
||||
To limit this ability for just one specific database, use this:
|
||||
|
||||
.. code-block:: json
|
||||
|
||||
{
|
||||
"databases": {
|
||||
"mydatabase": {
|
||||
"allow_sql": {
|
||||
"id": "root"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.. _authentication_actor_matches_allow:
|
||||
|
||||
actor_matches_allow()
|
||||
|
|
|
|||
|
|
@ -150,15 +150,6 @@ Should users be able to download the original SQLite database using a link on th
|
|||
|
||||
datasette mydatabase.db --config allow_download:off
|
||||
|
||||
.. _config_allow_sql:
|
||||
|
||||
allow_sql
|
||||
~~~~~~~~~
|
||||
|
||||
Enable/disable the ability for users to run custom SQL directly against a database. To disable this feature, run::
|
||||
|
||||
datasette mydatabase.db --config allow_sql:off
|
||||
|
||||
.. _config_default_cache_ttl:
|
||||
|
||||
default_cache_ttl
|
||||
|
|
|
|||
|
|
@ -291,7 +291,7 @@ Special table arguments
|
|||
though this could potentially result in errors if the wrong syntax is used.
|
||||
|
||||
``?_where=SQL-fragment``
|
||||
If the :ref:`config_allow_sql` config option is enabled, this parameter
|
||||
If the :ref:`permissions_execute_sql` permission is enabled, this parameter
|
||||
can be used to pass one or more additional SQL fragments to be used in the
|
||||
`WHERE` clause of the SQL used to query the table.
|
||||
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@ Database
|
|||
========
|
||||
|
||||
Each database has a page listing the tables, views and canned queries
|
||||
available for that database. If the :ref:`config_allow_sql` config option is enabled (it's turned on by default) there will also be an interface for executing arbitrary SQL select queries against the data.
|
||||
available for that database. If the :ref:`permissions_execute_sql` permission is enabled (it's on by default) there will also be an interface for executing arbitrary SQL select queries against the data.
|
||||
|
||||
Examples:
|
||||
|
||||
|
|
|
|||
|
|
@ -12,8 +12,8 @@ you like. You can also construct queries using the filter interface on the
|
|||
tables page, then click "View and edit SQL" to open that query in the custom
|
||||
SQL editor.
|
||||
|
||||
Note that this interface is only available if the :ref:`config_allow_sql` option
|
||||
has not been disabled.
|
||||
Note that this interface is only available if the :ref:`permissions_execute_sql`
|
||||
permission is allowed.
|
||||
|
||||
Any Datasette SQL query is reflected in the URL of the page, allowing you to
|
||||
bookmark them, share them with others and navigate through previous queries
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue