forked from geoserver/geoserver
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[GEOS-11616] GSIP 229 - File system access isolation (geoserver#8052)
* [GEOS-11616] GSIP 229 - File system access isolation * [GEOS-11616] GSIP 229 - File system access isolation. Windows compatibility
- Loading branch information
Showing
48 changed files
with
1,926 additions
and
112 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
.. _security_sandbox: | ||
|
||
Filesystem sandboxing | ||
===================== | ||
|
||
GeoServer administrators can usually explore the full file system of the server where GeoServer | ||
is running into, with the same privileges as the user running the servlet container. | ||
|
||
This can be limited by setting up a sandbox, which will restrict the access to the file system | ||
to a specific directory tree. The sandbox can be set up at two levels: | ||
|
||
* **System sandbox**: the GeoServer administrator is sandboxed into a specific directory, and won't be | ||
able to access files outside of it, nor change the sandbox configuration. | ||
* **Regular sandbox**: the GeoServer administrator can still access the full file system, but can set up | ||
a sandbox for each workspace, where the workspace administrators will be sandboxed into. | ||
|
||
.. warning:: The importer extension allows upload of data and is currently unable to respect the file system sandbox, | ||
it uses a configurable location inside the data directory instead. Store creation will fail if the importer | ||
is used and the sandbox is set. | ||
|
||
Setting up a system sandbox | ||
--------------------------- | ||
|
||
The system sandbox is configured by setting the ``GEOSERVER_FILESYSTEM_SANDBOX`` variable to the | ||
directory where the GeoServer administrator should be sandboxed into. | ||
The variable can be provided as a Java system variable, as a servlet context parameter, or as an | ||
environment variable, please consult the :ref:`application_properties` section for more details. | ||
|
||
When the system sandbox is set: | ||
|
||
* The GeoServer administrator will be sandboxed into the configured directory, | ||
and won't be able to access files outside of it, nor change the sandbox configuration. | ||
* The GeoServer workspace administrators will be sandboxed into ``<sandbox>/<workspace>``, where | ||
``<workspace>`` is the name of any workspace they can access. | ||
|
||
The system sandbox is best suited in hosting environments, where the GeoServer administrator and the | ||
operating system administrator are different people, and the GeoServer administrator should not be | ||
able to access the full file system. | ||
|
||
Setting up a regular sandbox | ||
---------------------------- | ||
|
||
The regular sandbox can be configured by GeoServer full administrators in the user interface, | ||
from the :guilabel:`Security` -> :guilabel:`Data` page, or by adding the following entry in the | ||
``layers.properties`` file: | ||
|
||
.. code-block:: properties | ||
# Set the sandbox for the workspace | ||
filesystemSandbox=/path/to/sandbox | ||
When the regular sandbox is set: | ||
|
||
* The GeoServer administrator will still be able to access the full file system, | ||
as well as change the sandbox configuration if they so desire. | ||
* The GeoServer workspace administrators will be sandboxed into ``<sandbox>/<workspace>``, where | ||
``<workspace>`` is the name of any workspace they can access. | ||
|
||
The regular sandbox is best suited in multi-tenant environments where the main GeoServer administrator | ||
also has access to the server operating system, while each tenant is modelled as a workspace | ||
administrator and should be able to manage its own data, but not access the data of other tenants. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
src/main/src/main/java/org/geoserver/catalog/event/AbstractCatalogListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* (c) 2024 Open Source Geospatial Foundation - all rights reserved | ||
* This code is licensed under the GPL 2.0 license, available at the root | ||
* application directory. | ||
*/ | ||
package org.geoserver.catalog.event; | ||
|
||
import org.geoserver.catalog.CatalogException; | ||
|
||
/** | ||
* A base class for {@link CatalogListener} that implements all listener methods without any action. | ||
* Useful for listeners that are only interested in a subset of events. | ||
*/ | ||
public class AbstractCatalogListener implements CatalogListener { | ||
|
||
@Override | ||
public void handleAddEvent(CatalogAddEvent event) throws CatalogException { | ||
// nothing to do | ||
} | ||
|
||
@Override | ||
public void handleRemoveEvent(CatalogRemoveEvent event) throws CatalogException { | ||
// nothing to do | ||
} | ||
|
||
@Override | ||
public void handleModifyEvent(CatalogModifyEvent event) throws CatalogException { | ||
// nothing to do | ||
} | ||
|
||
@Override | ||
public void handlePostModifyEvent(CatalogPostModifyEvent event) throws CatalogException { | ||
// nothing to do | ||
} | ||
|
||
@Override | ||
public void reloaded() { | ||
// nothing to do | ||
} | ||
} |
67 changes: 67 additions & 0 deletions
67
src/main/src/main/java/org/geoserver/security/FileAccessManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/* (c) 2024 Open Source Geospatial Foundation - all rights reserved | ||
* This code is licensed under the GPL 2.0 license, available at the root | ||
* application directory. | ||
*/ | ||
package org.geoserver.security; | ||
|
||
import java.io.File; | ||
import java.util.List; | ||
import org.geoserver.platform.GeoServerExtensions; | ||
import org.geoserver.security.impl.DefaultFileAccessManager; | ||
import org.springframework.security.core.Authentication; | ||
import org.springframework.security.core.context.SecurityContextHolder; | ||
|
||
/** | ||
* Provides the GUI, REST API and catalog checks with directives on what parts of the file system | ||
* the current user can access. | ||
*/ | ||
public interface FileAccessManager { | ||
/** | ||
* Returns the file system roots available for the current user (or <code>null</code> if there | ||
* are no restrictions) | ||
*/ | ||
public List<File> getAvailableRoots(); | ||
|
||
/** | ||
* Returns the sandbox root directory, if there is one, or <code>null</code> if there is none | ||
* (i.e., the user can access the whole file system). This is used by the REST API to | ||
* automatically prepend the sandbox root to the uploaded file paths. | ||
*/ | ||
public File getSandbox(); | ||
|
||
/** | ||
* Checks if the specified file is accessible in the context of the current request | ||
* | ||
* @param file the file to check | ||
*/ | ||
public boolean checkAccess(File file); | ||
|
||
/** | ||
* Looks up the {@link FileAccessManager} to use, preferring a custom implementation if | ||
* available, otherwise falling back on the default one. Mimics the behavior in {@link | ||
* org.geoserver.security.SecureCatalogImpl} | ||
*/ | ||
public static FileAccessManager lookupFileAccessManager() { | ||
List<FileAccessManager> managers = GeoServerExtensions.extensions(FileAccessManager.class); | ||
if (managers.isEmpty()) | ||
throw new RuntimeException("Unexpected, no FileAdminAccessManager found"); | ||
|
||
FileAccessManager manager = null; | ||
for (FileAccessManager resourceAccessManager : managers) { | ||
if (!DefaultFileAccessManager.class.equals(resourceAccessManager.getClass())) { | ||
manager = resourceAccessManager; | ||
break; | ||
} | ||
} | ||
|
||
// no custom manager found? | ||
if (manager == null) manager = managers.get(0); | ||
|
||
return manager; | ||
} | ||
|
||
/** Returns the current user authentication */ | ||
default Authentication user() { | ||
return SecurityContextHolder.getContext().getAuthentication(); | ||
} | ||
} |
Oops, something went wrong.