Firestore in Datastore mode offers compatibility with the older Datastore service but does not support the granular, document-level security rules that are available in Firestore in Native mode. Instead, access control is managed exclusively through IAM, which operates at the project and service level rather than at the individual document level.
IAM
- IAM Roles: Assign predefined IAM roles such as
roles/datastore.user(read-write access),roles/datastore.viewer(read-only access), androles/datastore.owner(full administrative access) to users or service accounts. This approach provides broader, but less granular, permissions compared to Firestore security rules. - Management Tools: Use the Google Cloud Console (navigate to “IAM & Admin” > “IAM”) or the
gcloudCLI to manage IAM policies effectively.
Differences from Native Firestore:
- No Firestore Security Rules: Commands like
gcloud firestore security-rules updateare not applicable in Datastore mode because security rules are not supported. - No Emulator or Rules Playground: These testing tools, which are available for Firestore in Native mode, are not available in Datastore mode. Testing IAM policies typically involves applying them directly and observing their effects in the operational environment.
Additional Considerations:
- Granularity: If your application requires fine-grained, document-level permissions, Firestore in Native mode is the appropriate choice.
- Migration: Migrating from Datastore mode to Native mode involves significant planning and effort, especially for large datasets. It’s important to carefully evaluate the benefits and challenges associated with such a migration.
Example (gcloud CLI):
gcloud projects add-iam-policy-binding your-project-id \
--member='user:jane@example.com' \
--role='roles/datastore.user'
This command grants read-write access to the user “jane@example.com” for your Firestore database in Datastore mode.
By understanding these key distinctions and leveraging IAM effectively, you can confidently manage access control for your Firestore database in Datastore mode. This setup ensures broad access control that, while not as fine-grained as Firestore’s security rules, still provides robust management capabilities for large-scale applications.